Apache 中使用查询字符串和域名进行 301 重定向
我正在尝试编写一个 301 重定向,它将同时查看主机名和查询字符串参数。因此,如果 URL 是两者之一。
然后我希望它重定向到适当的页面:
否则,如果主机不是example.com,如
然后我不希望它重定向。
这是我到目前为止所拥有的,但它似乎不起作用。如果有人可以在这方面提供一点帮助,我们将不胜感激。我已经尝试找到类似的答案,但找不到。
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteCond %{query_string} p=11&b=3
RewriteRule (.*) http://store.example.com/testpage.html [R=301,L]
I'm trying to write a 301 redirect that will look at both the host name and the query string parameter. So if the URL is either of the two.
Then I want it to redirect to the appropriate page:
Otherwise, if host is not example.com like
Then I do not want it to redirect.
This is what I have so far, but it doesn't seem to work. If anyone could provide a bit of help on this one, it would be most appreciated. I already tried to find a similar answer but I couldn't find one.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteCond %{query_string} p=11&b=3
RewriteRule (.*) http://store.example.com/testpage.html [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为替换 URL 指定一个空查询:
否则原始请求的查询将自动附加到新 URL。
You need to specify an empty query for your substitution URL:
Otherwise the original requested query gets automatically appended to the new URL.