htaccess重写匹配精确的查询字符串

时间:2012-12-11 12:53:04

标签: .htaccess

我正在尝试将main/WinnersDetails.asp?ID=167的请求重定向到http://www.the-domain-name.org.uk/winners/simon-bingham.html。但是,我的重写规则无效。

RewriteRule ^main/WinnersDetails.asp?ID=167$ http://www.the-domain-name.org.uk/winners/simon-bingham.html [R=301]

我认为这是导致重定向失败的url的查询字符串部分,但我不确定如何修改规则以使其工作。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

您无法匹配重写规则中的查询字符串。您需要在重写条件中匹配%{QUERY_STRING}变量:

RewriteCond %{QUERY_STRING} ^ID=167$ 
RewriteRule ^main/WinnersDetails.asp$ http://www.the-domain-name.org.uk/winners/simon-bingham.html? [R=301,L]