.HTACCESS 重定向 301 从根目录到子目录的所有文件

.HTACCESS Redirect 301 all files from root directory to sub directory

我正在尝试将访问我的网站根目录的用户重定向到子目录。

我正在尝试这个:

//301 重定向整个目录

RedirectMatch 301 /(.*) /1.0/projects/navigator/

但是还是不行,而是重复多次子目录的路径:

[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/

如何操作?

提前致谢

将以下代码放在根目录.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/ [R=301,L]

您必须排除要重定向到的路径:

RedirectMatch 301 /((?!1.0/projects/navigator).*) /1.0/projects/navigator/

否则你会得到一个重定向循环错误因为/1.0/projects/navigator/ 也匹配模式 /(.*) 并多次将请求重定向到同一目的地。

在测试之前清除浏览器的缓存。