mod_alias 子目录替换

发布于 2024-08-13 17:18:23 字数 585 浏览 3 评论 0原文

我使用 RewriteMatch 将所有流量从 subdir1 重定向到 subdir2,同时保持 url 的所有其他部分相同。例如,

http://www.mydomain.com/subdir1/

将重定向到

http://www.mydomain.com/subdir2/

我正在使用此规则:

RedirectMatch 302 /subdir1/.* /subdir2/$1

该规则适用于 url

http://www.mydomain.com/subdir1/

,但不适用于任何具有较长 url 的页面。所以它不匹配

http://www.mydomain.com/subdir1/index.htm

,应该重定向到

http://www.mydomain.com/subdir2/index.htm

如果有人有任何想法,我将不胜感激。

I am using RewriteMatch to redirect all traffic from subdir1 to subdir2, while keeping all other parts of the url the same. So for instance,

http://www.mydomain.com/subdir1/

would redirect to

http://www.mydomain.com/subdir2/

I am using this rule:

RedirectMatch 302 /subdir1/.* /subdir2/$1

which works for the url

http://www.mydomain.com/subdir1/

but not for any pages with longer urls. So it is not matching

http://www.mydomain.com/subdir1/index.htm

which should be redirected to

http://www.mydomain.com/subdir2/index.htm

If anyone has any ideas, I'd appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

注定孤独终老 2024-08-20 17:18:23

您需要在 .* 周围加上括号,

RedirectMatch 302 /subdir1/(.*) /subdir2/$1

否则 $1 就没有意义,并且不会“知道”要匹配什么。

You would need to round brackets around your .*

RedirectMatch 302 /subdir1/(.*) /subdir2/$1

Without that $1 is meaningless and is not going to 'know' what to match on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文