如何使用mod_rewrite规则将一个url转发到另一个url

时间:2010-01-22 14:41:31

标签: mod-rewrite

我试图转发此网址,但它不起作用 - 这是我的代码:

RewriteRule ^https://www.wsjwine.com/discovery_offer.aspx?promo=2227006$ https://www.wsjwine.com/discovery_offer_lp2.aspx?promo=2227006 [L]

2 个答案:

答案 0 :(得分:0)

您无法检测到类似的查询字符串。使用RewriteCond %{QUERY_STRING}

答案 1 :(得分:0)

使用RewriteRule directive,您只能测试URL path。要进一步测试,您需要使用额外的RewriteCond directives

现在,如果您想将 /discovery_offer.aspx 的每个请求重写为 /discovery_offer_lp2.aspx 而不管查询的外观如何,您可以使用它(例如对于根目录中的.htaccess文件):

RewriteRule ^discovery_offer\.aspx$ discovery_offer_lp2.aspx [L]

如果您未在替换中指定查询,则原始请求的查询会自动附加到新查询。

如果您只想重写该特定网址,请尝试以下方法:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} =www.wsjwine.com
RewriteCond %{QUERY_STRING} =promo=2227006
RewriteRule ^discovery_offer\.aspx$ discovery_offer_lp2.aspx [L]