2016-06-28 182 views
1

昨天我在服務器上安裝了SSL。由於我無法訪問某些頁面。重定向非www和非http到https

www.example.com/amsterdam/shoes

example.com/amsterdam/

^都沒有自動跳轉到https://,甚至不是HTTP://

www.example.com/amsterdam

^並重定向到HTT ps://

如何使用www通過.htaccess將所有頁面重定向到HTTPS?

+0

[阿帕奇的可能的複製重定向HTTP到HTTPS和www到非www](http://stackoverflow.com/questions/9945655/apache-redirect-http-to -https-和WWW的對非www) –

回答

7
RewriteEngine on 


RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule^https://www.example.com%{REQUEST_URI} [NC,L] 

這將重定向都httpnon-wwwhttps://www

0

用途:

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

或者你可以嘗試:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 
相關問題