htaccess将非www重定向到www而不会丢失脚本和查询

时间:2015-01-27 19:27:35

标签: apache .htaccess redirect

我想从此重定向:

http://example.com/admin/index.php?route=common/home&token=e687040d4b0f5f42a4eab8951a3b57b4

对此:

http://www.example.com/admin/index.php?route=common/home&token=e687040d4b0f5f42a4eab8951a3b57b4

我的htaccess:

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

但它重定向我:

http://www.example.com/index.php?route=common/home&token=e687040d4b0f5f42a4eab8951a3b57b4

1 个答案:

答案 0 :(得分:0)

使用此:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]