RewriteRules 重复部分匹配

发布于 2024-09-30 02:06:38 字数 641 浏览 0 评论 0原文

我想要实现的是尝试匹配子域和完整路径,以便重定向到没有 www 的版本。在它的前面。为此,我使用:

RewriteCond %{HTTP_HOST} ^www\.(.+).mydomain.com$ [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [C]
RewriteRule ^www\.(.+)\.mydomain\.com/(.*)$ http://$1.mydomain.com/$2 [R=permanent,L]

如果我请求类似以下内容,则可以正常工作:

www.me.mydomain.com/page

它重定向到:

me.mydomain.com/page

但是,如果我输入:

www.me.mydomain.com/page/other

它重定向到:

me.mydomain.com/page/other/other

它总是重复第一个斜杠之后的部分。我无法找出导致重复的原因。 (我实际上在更复杂的情况下遇到了这个问题,但这是我可以重现它的最简单的版本)

What I'm trying to achieve is trying to match both the subdomain and the full path in order to redirect to a version without www. in front of it. To do so I use:

RewriteCond %{HTTP_HOST} ^www\.(.+).mydomain.com$ [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [C]
RewriteRule ^www\.(.+)\.mydomain\.com/(.*)$ http://$1.mydomain.com/$2 [R=permanent,L]

This works ok if I request something like:

www.me.mydomain.com/page

It redirects to:

me.mydomain.com/page

However, if I enter:

www.me.mydomain.com/page/other

It redirects to:

me.mydomain.com/page/other/other

It always repeats the part after the first slash. I can't find out what is causing the repetition. ( I actually encountered the problem in a more complex case, but this was the most simple version I could reproduce it with)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文