2017-06-30 32 views
0

我想強制一個網站的https,但它只適用於如果我鍵入www.example.com,而不是當我使用example.com。這裏是我的htaccess文件:如何使用example.com的.htaccess強制使用HTTPS?

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

你們能幫助我嗎?

回答

0

然後把這些線以上HTTPS條件

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
RewriteRule ^(.*)$ "https\:\/\/example\.com\/$1" [R=301,L] 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

謝謝,它的工作原理! –

+0

更改爲'RewriteRule ^(。*)$ https://example.com/$1 [R = 301,L]'在https之前不需要重定向到http – Croises

+0

@Croises感謝您指出。 – lkdhruw