Hide directory with htaccess

I am trying to hide the users url directory (e.g. :): meusite.com.br/users/teste , but so far this has failed. Similarly, referring to meusite.com.br/teste , show the contents inside the teste folder and if access to the URL meusite.com.br/users/teste , /users/ were deleted and only meusite.com.br/teste .

I tried:

 RewriteCond %{REQUEST_URI} !^/users RewriteRule (.*) /users/$1 [QSA,L] 

but I did not succeed. I also tried:

 RewriteCond %{REQUEST_URI} !^/users RewriteRule ^/?([^/]+)$ /users/$1 [L] 

but does not work.

For a better understanding, this follows from the folder structure of the site:

 ├── users | ├── teste | | └── index.html | └── outroteste | └── index.html ├── .htaccess └── index.php 

As my "htaccess" file already exists:

 <IfModule mod_rewrite.c> RewriteEngine On # Rewrites the requested http to https. RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} # Hide GET variables link. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^posts/(.*) posts.php?p=$1 </IfModule> 

Hope you can help.

+5
source share
1 answer

You can use the users hide rule only below the redirection rule:

 DirectorySlash Off RewriteEngine On # Rewrites the requested http to https. RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301] # add a trailing slash to directories RewriteCond %{DOCUMENT_ROOT}/users/$1/ -d RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302,NE] RewriteCond %{THE_REQUEST} /users/(\S*)\s [NC] RewriteRule ^ /%1 [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?((?!users/).*)$ users/$1 [L,NC] # Hide GET variables link. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^posts/(.*) posts.php?p=$1 [L,QSA] 

But just keep in mind that it will forward everything to /users/ , thereby violating the last rule.

+2
source

All Articles