2016-11-12 51 views
0

我已经使用letsencrypt为域example.comwww.example.com创建了一个SSL证书并将其上传到我的托管软件包。该证书似乎工作得很好,如果我打开https://www.example.com该网站被标记为安全。https和www重定向的问题

现在我想通过.htaccess文件基本上强制使用httpswww

example.com --> https://www.example.com 
www.example.com --> https://www.example.com 
https://example.com --> https://www.example.com 
http://www.example.com --> https://www.example.com 

到目前为止,我已经尝试了几个不同的重写规则在这里从SO,但似乎没有为https使用加www。它总是说ERR_CONNECTION_REFUSED当开放https://example.com
我再次检查了证书https://www.sslshopper.com/certificate-decoder.html,它列出了正确的地址(example.comwww.example.com)。我的托管包说www子域是预先配置的,不能更改。

希望有人能解释我需要做什么或出什么问题。
我也想知道,如果我想做的事情很好,或者我在这里做的不好。

+0

你能告诉我们你现在的尝试? – anubhava

+0

我试过的最后一个是从这两个职位:http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www和http://stackoverflow.com/questions/24711083/forcing-ssl-和-www-using-htaccess – 0x1234

回答

1

您可以使用此单一规则为您第一条规则执行httpswww

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. [NC,OR] 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] 
RewriteRule^https://www.%1%{REQUEST_URI} [R=301,L,NE] 

# --- remaining rules go below this --- 
+0

@ 0x1234:这是否工作? – anubhava

相关问题