开发者

.htaccess - adding sub directory to all directories

开发者 https://www.devze.com 2023-04-01 11:20 出处:网络
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.

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]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号