2016-11-19 114 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

相關問題