1

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

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

当我到处搜索并尝试了很多方法来尝试使其正常工作时,它变得如此沮丧。希望这里有人可以帮助我!

这是我需要重定向的几个网址:

/store/index.php?search=人字拖 >> http://www.stonemenswear.co.uk/menswear/flip-flops

/store/index.php?search=Boss+Orange+短裤 >> 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]

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

这些中的每一个都被重定向到人字拖页面!

提前致谢。

4

2 回答 2

0

错误使用标志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]
于 2013-08-30T10:30:50.987 回答
0

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

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]
于 2017-09-26T11:01:24.613 回答