我正在尝试重定向网址
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点不起作用
有没有解决方案?
答案 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]