我写过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]`
但如果某些用户访问direclty 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]
答案 0 :(得分:0)
你无法像那样操纵查询字符串。你需要使用RewriteCond
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=information/partnership_form [NC]
RewriteRule ^index\.php$ /for-brands/partner-with-us? [NC,L,R]
重写目标末尾的?非常重要,因为它会丢弃旧的查询字符串。