我基本上想要:
http://example.com/index.php?page=abc重定向到http://www.exmaple.com/abc
我有:
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^index.php$ %1? [R=301]
RewriteRule ^%1$ index.php?page=%1 [L]
我基本上想要:
http://example.com/index.php?page=abc重定向到http://www.exmaple.com/abc
我有:
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^index.php$ %1? [R=301]
RewriteRule ^%1$ index.php?page=%1 [L]
第二条规则中的一些语法问题和第一条规则中的逻辑问题。
以下应该工作:
RewriteEngine On
# for external redirection from `/index.php?page=abc` to `/abc`
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# for internal redirection from `/abc` to `/index.php?page=abc`
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]