2017-04-25 84 views
0

我写的htaccess重写 我实际的URL是重定向URL已经在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

下面

是我的代码重定向,但我已经尝试过很多办法形成计算器等环节仍然我找不到任何解决方案

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

回答

0

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

RewriteEngine on 

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

?重写目标末尾的非常重要,因为它会丢弃旧的querystrings。

+0

我试过了你的代码,但是它的retuning error这个页面没有正确的重定向,如果我在'rewriteRule^index \ .php $/for-sports-brands/partner-with-我们? [NC,L,R]' –