htaccess多个查询字符串重定向到不同的url


htaccess multiple query string redirects to different urls

我对在htaccess中尝试重定向完全陌生,但我有一个大约20个URL的列表,所有URL都有查询字符串,并且都指向不同的URL。

我已经成功地使用使用RewriteCond和RewriteRule的查询字符串进行了重定向,但当我以相同的格式添加其他url时,它们似乎都重定向到了第一个Rewriteule中的url。

当我到处寻找并尝试了很多方法来实现这一点时,我感到非常沮丧。希望这里有人能帮助我!

以下是我需要重定向的几个url:

/store/index.php?search=触发器>>http://www.stonemenswear.co.uk/menswear/flip-flops

/store/index.php?search=老板+橙色+短裤>>http://www.stonemenswear.co.uk/menswear/shorts

这是我迄今为止得到的代码:

RewriteEngine on
RewriteCond "%{QUERY_STRING} search=flip flops" 
RewriteRule ^index'.php$ http://www.stonemenswear.co.uk/menswear/flip-flops/? [R=301,N]
RewriteCond %{QUERY_STRING} search=Boss+Orange+Shorts 
RewriteRule ^index'.php$ http://www.stonemenswear.co.uk/menswear/shorts? [R=301,N]

(加上其他相同格式的重写)

每一个都被重定向到触发器页面!

提前谢谢。

错误使用标志N您需要L标志。将您的代码替换为:

RewriteCond "%{QUERY_STRING} search=flip flops" [NC]
RewriteRule ^store/index'.php$ http://www.stonemenswear.co.uk//menswear/flip-flops/? [R=301,L,NC]
RewriteCond %{QUERY_STRING} ^search=Boss'+Orange'+Shorts(&|$) [NC]
RewriteRule ^store/index'.php$ http://www.stonemenswear.co.uk/menswear/shorts/? [R=301,L,NC]

这里有一些小的语法错误。

RewriteCond %{QUERY_STRING} "^search=flip flops$" [NC]
RewriteRule ^store/index'.php$ http://www.stonemenswear.co.uk/menswear/flip-flops/? [R=301,L]
RewriteCond %{QUERY_STRING} ^search=Boss'+Orange'+Shorts$ [NC]
RewriteRule ^store/index'.php$ http://www.stonemenswear.co.uk/menswear/shorts/? [R=301,L]