RewriteRules 重复部分匹配
我想要实现的是尝试匹配子域和完整路径,以便重定向到没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论