.htaccess从一个子文件夹重定向到另一子文件夹 [英] .htaccess redirect from one subfolder to other subfolder

查看:77
本文介绍了.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 已启用,请参见此答案有关调试.htaccess重写规则的提示以了解详细信息。

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

这篇关于.htaccess从一个子文件夹重定向到另一子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆