Apache RewriteRule查询字符串中的多个变量

时间:2013-08-23 15:08:30

标签: apache .htaccess mod-rewrite

我一直试图弄清楚如何写一个新的重写规则,但我正在苦苦挣扎。我们正在从domain.com删除全球(WW)网站,并希望将任何旧链接转发到国家/地区选择器。任何帮助,将不胜感激。提前谢谢。

# if any user goes to this URL
www.domain.com/products/folder1/folder2/index?sku=123&var2=abc&isocountrycode=ww

# forward them to this URL
www.domain.com/choose/country_selection?ref_url=/products/folder1/folder2/index.cfm?sku=123&var2=abc

# my attempt that does not work
RewriteCond %{QUERY_STRING}     ^(.*)isocountrycode=ww(.*)$    [NC]
RewriteRule ^(.+)$      /choose/country_selection.cfm?ref_url=$1?%1%2 [L,R=302]

我一直在使用此网站测试我的代码http://martinmelin.se/rewrite-rule-tester/

1 个答案:

答案 0 :(得分:0)

回答了我自己的问题。 Helicontech APE需要第二个?用反斜杠逃脱...

RewriteCond %{QUERY_STRING} ^(.+&)?isocountrycode=ww&(.+)?$ [NC]
RewriteRule ^(.+)$ /choose/country_selection.cfm?ref_url=/$1\?%1%2? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^((.+)&)?isocountrycode=ww$ [NC] 
RewriteRule ^(.+)$ /choose/country_selection.cfm?ref_url=/$1\?%2? [NC,R=301,L]