Htaccess 使用查询字符串重定向 RewriteRule 301

Htaccess Redirect RewriteRule 301 with query strings

我有很多这样的链接想做301

RewriteRule ^best-sales?n=10&p=10$ http://www.bestbuyuniforms.com/best-sales [L,R=301]
RewriteRule ^3_dickies?n=24&id_manufacturer=3$ http://www.bestbuyuniforms.com/3_dickies [L,R=301]
RewriteRule ^imgcmsWilcox%20Culinary%20Arts%20Department.pdf$ http://www.bestbuyuniforms.com [L,R=301]

这些链接

RewriteRule ^157-port-authority-silk-touch-interlock-sport-shirt.html$ http://www.bestbuyuniforms.com/hospitality-housekeeping-polo-shirts/137--port-authority-silk-touch-sport-shirt-with-pocket.html [L,R=301]
RewriteRule ^145-port-authority-extended-size-silk-touch-sport-shirt.html$ http://www.bestbuyuniforms.com/ladies-workwear/151-port-authority-ladies-silk-touch-interlock-sport-shirt.html [L,R=301]
RewriteRule ^217-hanes-stedman-52-ounce-jersey-knit-sport-shirt.html$ http://www.bestbuyuniforms.com/apparel/2329-hanes-comfortblend-ecosmart-jersey-knit-sport-shirt-with-pocket-.html [L,R=301]
RewriteRule ^134-port-authority-long-sleeve-silk-touch-sport-shirt-with-pocket-.html$ http://www.bestbuyuniforms.com/ladies-workwear/132-port-authority-ladies-long-sleeve-silk-touch-sport-shirt-L500LS.html [L,R=301]

没有查询字符串完全重定向相同的规则,但有查询字符串或 %20% 的重定向问题。

无法匹配重写规则中的查询字符串,需要使用%{QUERY_STRING}和重写条件。

所以:

RewriteCond %{QUERY_STRING} ^n=10&p=10$
RewriteRule ^best-sales$ http://www.bestbuyuniforms.com/best-sales? [L,R=301]

RewriteCond %{QUERY_STRING} ^n=24&id_manufacturer=3$
RewriteRule ^3_dickies$ http://www.bestbuyuniforms.com/3_dickies? [L,R=301]