2016-11-19 90 views
0

我有一个全新的网站,最初,它是http://然后我重定向网站到http://www它工作喜欢魅力,但因为我安装SSL我有两个版本的网站http://www.example.comhttps://www.example.com。 我试图在.htaccess几个命令,但我仍然有两个版本,有人可以帮我这个问题,以下是我用我的.htaccess代码:将所有流量重定向到https:// www。目前我有两个版本http:// www和https:// www

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

回答

1

首先WWW和https后:

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

在测试之前清除缓存或尝试使用其他浏览器 – Croises

+0

Thanks @croises。我已清除浏览器中的缓存,清漆并重新启动apache,但仍然转到http:// www –

+0

问题不在于此htaccess。当然在服务器配置 – Croises

0

试试这个。

RewriteEngine On 
RewriteCond %{HTTPS} off 
# First rewrite to HTTPS: 
# Don't put www. here. If it is already there it will be included, if not 
# the subsequent rule will catch it. 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
# Now, rewrite any request to the wrong domain to use www. 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

不,因为您不使用www重定向到https,而使用www = 2 x 301重定向重新导向。如果您先不使用www重定向到https // www,则在https之后不需要重定向。这在问题中是一样的... – Croises

+0

Ooops,我只注意到它和问题中的一样。我的错 :\ – jsalatas

相关问题