【问题标题】:redirect url already rewritten in htaccess重定向 url 已经在 htaccess 中重写
【发布时间】:2017-04-25 06:18:44
【问题描述】:

我已经写了 htaccess 我的实际网址是

https://www.example.com/index.php?route=information/partnership_form

改写为

https://www.example.com/for-brands/partner-with-us

效果很好,因为我已经写了规则

`RewriteRule ^for-brands/partner-with-us$ https://www.example.com/index.php?route=information/partnership_form [NC,L]`

但如果某些用户直接访问https://www.example.com/index.php?route=information/partnership_form,我想要重定向

https://www.example.com/for-brands/partner-with-us

下面是我的代码重定向,但我已经尝试了很多方法来形成 stackoverflow 的其他链接,但我仍然找不到任何解决方案

rewriterule ^index\.php?route=information\/partnership_form(.*)$ /for-sports-brands/partner-with-us$1 [r=301,nc]

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    你不能像那样操作查询字符串。您需要使用 RewriteCond

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^route=information/partnership_form [NC]
    RewriteRule ^index\.php$ /for-brands/partner-with-us? [NC,L,R]
    

    重写目标末尾的 ? 很重要,因为它会丢弃旧的查询字符串。

    【讨论】:

    • 我试过你的代码,但它的重新调整错误页面没有正确重定向,如果我在RewriteRule ^index\.php$ /for-sports-brands/partner-with-us? [NC,L,R]这样的重写器中写运动会有什么不同
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 2011-01-26
    • 2013-12-21
    • 2015-03-04
    • 2014-11-26
    相关资源
    最近更新 更多