繁体   English   中英

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

[英]htaccess multiple query string redirects to different urls

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

我设法通过使用RewriteCond和RewriteRule的查询字符串来获得重定向,但是当我以相同格式添加其他URL时,它们似乎都重定向到第一个RewriteRule中的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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM