Hiding folder in URL using .htaccess

2019-09-03 05:33发布

问题:

I need to hide a folder from a url.

An example:

If I enter www.mysite.com/Jango I need you to read the directory: www.mysite.com/users/Jango but do not want to see /users

I just want to see this in the address bar: www.mysite.com/Jango

回答1:

This .htaccess in / should do:

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

This treats any requset not starting with users/ as if it did.

Update:
If you want the rule to apply for only /Jango --> /users/Jango, this would be an appropriate .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^users/Jango
RewriteRule ^Jango/(.*)$ users/Jango/$1 [L]

(The [L]-flag stops rewriting afther this rule, preventing possible circle-reactions etc)