.htaccess http到https和mvc查询字符串

时间:2015-02-05 18:30:15

标签: apache .htaccess http redirect https

所以,问题是,在我的VirtualHosts中,我重定向到https,其后面是:

...
Redirect permanent / https://www.example.com/
...

然后在.htaccess中我

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]

但在输入http://example.com时,在网址中显示https://www.example.com/ ?_ url = /

为什么不应该出现“?_url = /”。 Apache版本:2.4.7

1 个答案:

答案 0 :(得分:2)

从Apache配置中注释掉这一行:

Redirect permanent / https://www.example.com/

然后在root .htaccess中使用此代码:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?_url=/$1 [QSA,L]