【问题标题】:htaccess multiple query string redirects to different urlshtaccess 多个查询字符串重定向到不同的 url
【发布时间】:2013-08-30 10:11:21
【问题描述】:

我对在 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]

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

每一个都被重定向到人字拖页面!

提前致谢。

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    错误使用标志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]
    

    【讨论】:

    • 您好,感谢您的快速回复。不幸的是,它对我不起作用。虽然,我在自己的代码中意识到了一个错误,但我猜测规则应该以 /store/index 而不是索引开头。我将如何将其纳入您刚才的建议中。谢谢
    • 谢谢,但它现在根本没有重定向,它只是继续显示旧页面。
    • 还是不开心!它甚至还没有尝试重定向。
    • 在发布最新答案之前,我已经测试过代码可以正常工作。
    • 仍然不适合我,只是将我带到旧页面。清算现金和一切。啊,好吧,无论如何感谢您的帮助:)
    【解决方案2】:

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

    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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-23
      • 2022-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      相关资源
      最近更新 更多