2017-10-11 82 views
0

我有我的SSL证书域,我想重定向一切使用https://www.example.com(以https和www)重定向组合

这是我到目前为止有:

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

然而,这两个组合不起作用,并显示apache2默认页面:

http://example.com 
http://www.example.com 

我错过了什么?

回答

0
RewriteEngine On 
RewriteCond %{HTTPS} off [OR] 
# line above to catch any request with http regradless of having www or not 
RewriteCond %{HTTP_HOST} !^www\. 
# line above to catch any request with https and without www 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=302,L,NE] 

所以,用(httphttps)和(www或无www)的任何请求将被重定向到https://www.example.com

注:清除浏览器缓存并对其进行测试,如果正常,改变302301以获得永久重定向