2017-01-02 62 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]