基于QUERY_STRING重写规则

时间:2017-03-24 06:00:40

标签: php apache .htaccess

我正在尝试重定向网址

www.mydomain.com/index.php?route=first/second to www.mydomain.com/second 我已经尝试了以下规则但似乎没有工作

   RewriteEngine On
1) RewriteRule ^index.php?route=first/second$ /second [R=301,L]
2) RewriteRule ^index.php?route=first/second$ www.mydomain.com/second [R=301,L]
3) Redirect ^index.php?route=first/second /second/
4) Redirect ^index.php?route=first/second www.mydomain.com/second/
5) Redirect ^www.mydomain.com/index.php?route=first/second /second/
6) Redirect ^www.mydomain.com/index.php?route=first/second www.mydomain.com/second/

但是以下规则有效: RewriteRule ^second$ /index.php?route=first/second [R=301,L]  但上面的第1点和第2点不起作用

有没有解决方案?

2 个答案:

答案 0 :(得分:0)

确保在任何规则之前加上RewriteEngine On

答案 1 :(得分:0)

确保:index.php存在,否则我们必须为file existence设置一些条件,例如RewriteCond %{REQUEST_FILENAME} !-f

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} route=first/second
RewriteRule .* /second? [R,L]