.htaccess - adding sub directory to all directories
Using .htaccess I am trying to add a directory to all URLs but don't seem to be having any luck. I can do it for each directory but was wondering if there is an easier way around this.
I need all my urls such as:
www.example.com/abc
www.example.com/def
www.example.com/ghi
to append the directory 'test' making the URLs look like this:
www.example.com/test/abc
www.example.com/test/def
ww开发者_JAVA技巧w.example.com/test/ghi
Tried with PHP but that seemed kind of silly so .htaccess seemed like the best bet.
Using mod_rewrite you can try adding this to your .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /test/$1 [L]
If you absolutely need a redirect (as opposed to a "behind-the-scenes" rewrite), change the [L]
to [R,L]
精彩评论