开发者

301 Redirect with query string and domain name in Apache

开发者 https://www.devze.com 2022-12-22 06:46 出处:网络
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.

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.

  • http://www.example.com/index.php?p=11&b=3
  • http://example.com/index.php?p=11&b=3

Then I want it to redirect to the appropriate page:

  • http://store.example.com/testpage.html

Otherwise, if host is not example.com like

  • http://www.example.net/index.php?p=11&b=3
  • http://example.net/index.php?p=11&b=3

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 apprecia开发者_开发知识库ted. 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]


You need to specify an empty query for your substitution URL:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{QUERY_STRING} p=11&b=3
RewriteRule .* http://store.example.com/testpage.html? [R=301,L]

Otherwise the original requested query gets automatically appended to the new URL.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号