REGEX .htaccess RewriteCond 参数形成
如何在 .htacess 中指定我希望对以 www.domain.com 开头的所有 URL 执行操作?
我想过RewriteCond %{HTTP_HOST} ^www.domain.com(.*)$ [NC]
但这是错误的。
也尝试过RewriteCond %{HTTP_HOST} ^www.domain.com(?:.*)?$ [NC]
但也好不到哪儿去。
How do I specify in .htacess that I want an action to be performed for all URLs beginning with www.domain.com?
I thought aboutRewriteCond %{HTTP_HOST} ^www.domain.com(.*)$ [NC]
but it's wrong.
Also triedRewriteCond %{HTTP_HOST} ^www.domain.com(?:.*)?$ [NC]
but isn't any better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已选择检查 HTTP_HOST 并据此做出决定。 HTTP_HOST 仅包含请求的主机名,不包含斜杠或完整 URL 的一部分。因此,我会删除 (.*) 或 (?:.*)?在 RewriteConds 末尾并再次检查。至少,我就是这样使用它的。
如果您尝试将 www 重定向到非 www(只是猜测)并希望确保传输请求的路径,这是我的代码:
它为搜索引擎使用 301“永久移动”重定向。
You have chosen to check against HTTP_HOST and make a decision based on that. HTTP_HOST only contains the hostname requested, and no slashes or parts of the full URL. Because of that, I would remove the (.*) or (?:.*)? at the end of your RewriteConds and check again. At least, that's how I use it.
If you're attemping to redirect a www to a non-www (just guessing) and want to make sure the requested path is transferred, this is my code:
It uses a 301 "Moved Permanently" redirect for search engines.