开发者

How to forward one url to another using mod_rewrite rules

开发者 https://www.devze.com 2022-12-17 01:17 出处:网络
Im trying to forward this url, but its not working - here is my code: RewriteRule ^https://www.wsjwine.com/discovery_offer.as开发者_运维技巧px?promo=2227006$ https://www.wsjwine.com/discovery_offer_l

Im trying to forward this url, but its not working - here is my code:

RewriteRule ^https://www.wsjwine.com/discovery_offer.as开发者_运维技巧px?promo=2227006$ https://www.wsjwine.com/discovery_offer_lp2.aspx?promo=2227006 [L]


With RewriteRule directive you can only test the URL path. For further tests you need to use additional RewriteCond directives.

Now if you want to rewrite every request of /discovery_offer.aspx to /discovery_offer_lp2.aspx regardless of how the query looks like, you can just use this (example for the .htaccess file in the root directory):

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

If you don’t specify a query in the substitution, the originally requested query is automatically appended to the new one.

And if you just want to rewrite that specific URL, try this:

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


You can't detect query strings like that. Use RewriteCond %{QUERY_STRING}.

0

精彩评论

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

关注公众号