.htaccess从一个子文件夹重定向到另一子文件夹
我知道这里听起来有很多其他问题,但是我似乎找不到答案。
I know this sounds like so many other questions here, but I can't seem to find the answer.
说你在用:
www .domain.com / folderA / folder2 / folder3 /
Say you are on: www.domain.com/folderA/folder2/folder3/
我希望将其重定向到:
www.domain.com/folderB/folder2/folder3/
I want that to redirect to: www.domain.com/folderB/folder2/folder3/
因此整个结构保持不变..它只是重定向。
到目前为止,我有:
So the whole structure stays the same.. it just redirects. Now so far I have:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/folderA [NC]
RewriteRule ^(.*)$ /folderB/$1 [R=301,L]
但是当我使用它时,它只会做
www.domain.com/folderB/folderA/folder2/folder3 /
But when I use that, it'll just do www.domain.com/folderB/folderA/folder2/folder3/
我在做什么错误?如何摆脱该文件夹A?
What am I doing wrong? How do I get rid of that folderA?
模式 ^(。*)$
还包括前缀 folderA
。您必须在模式中明确指定 folderA
并仅捕获RewriteRule中的后一部分。然后,您可以将RewriteCond
The pattern ^(.*)$
includes also the prefix folderA
. You must specify folderA
explicitly in the pattern and capture only the latter part in the RewriteRule. Then you can drop the RewriteCond
RewriteEngine on
RewriteRule ^/?folderA/(.*)$ /folderB/$1 [R,L]
从不对 301 $ c $进行测试c>已启用,请参见此答案有关调试.htaccess重写规则的提示以了解详细信息。
Never test with 301
enabled, see this answer Tips for debugging .htaccess rewrite rules for details.