我正在尝试将访问我的Web根目录的用户重定向到子目录。
我正在尝试这个:
// 301重定向整个目录
RedirectMatch 301 /(.*) /1.0/projects/navigator/$1
但是,它不起作用,但多次重复子目录的路径:
[my_domain] /1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0 /projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects /navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator /
怎么做?
提前致谢
答案 0 :(得分:1)
将以下代码放在根目录.htaccess
文件
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/1.0/projects/navigator/
# the above line will exclude the same sub directory from the rule below so
# no looping as what happened with you
RewriteRule ^(.*)$ /1.0/projects/navigator/$1 [R=301,L]
答案 1 :(得分:1)
您必须将要重定向的路径排除在:
RedirectMatch 301 /((?!1.0/projects/navigator).*) /1.0/projects/navigator/$1
否则您将收到重定向循环错误,因为/1.0/projects/navigator/
也匹配模式/(.*)
并将请求多次重定向到同一目的地。
在测试之前清除浏览器的缓存。