2012-06-22 61 views
0

我有一个htaccess的,看起来像这样:.htaccess重定向丢失查询字符串?

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
RewriteRule ^([^.]+)/?$ index.php?query=$1 [L] 

我希望这将使所有非www网址重定向到www的版本,以及给予在结束一个整洁的查询字符串。因此,这些网址:

http://site.com/index.php?query=test/page 
http://www.site.com/index.php?query=another/test/page 

两个都会重定向到:

http://www.site.com/test/page 
http://www.site.com/another/test/page 

分别。

然而,一切都只是重定向到:

http://www.site.com 

我在做什么错?

回答

0

RewriteRule忽略url中的查询字符串。所以,你需要改变你的规则如下:

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA] 

RewriteCond %{HTTP_HOST} ^www\. 
RewriteRule ^/index[.]php$ /%{QUERY_STRING} [L] 

请务必包括第一规则QSA标志

相关问题