2017-01-02 147 views
0

我試圖強制HTTPS對我的投資組合中的每個請求,也從網址中刪除WWW。我已經成功然而移除請求WWW當我嘗試強制使用HTTPS,我給出的「重定向過多」試圖刪除www和強制HTTPS

錯誤這是我的htaccess文件:

# remove www. from HTTPS requests 
 
RewriteCond %{HTTPS} on 
 
RewriteCond %{HTTP_HOST} ^www\.(patrickwhitehouse\.pw)$ [NC] 
 
RewriteRule .* https://%1/$0 [R,L] 
 

 
# redirect HTTP requests to HTTPS 
 
RewriteCond %{HTTPS} off 
 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(patrickwhitehouse\.pw)$ [NC] 
 
RewriteRule .* https://%1/$0 [R,L]

如果我手動輸入https://myurl.com,但它可以工作,但是當我訪問另一個頁面時,HTTPS會返回到HTTP。

回答

0

您的代碼正在重定向WWW。不刪除它。這是我一直在使用的相同問題的代碼。

### WWW & HTTPS 

#Remove WWW 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L] 

#Ensure https 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]