2012-01-11 51 views
0

我目前有:在.htaccess瞄准HTTPS重定向

RewriteCond %{HTTP_HOST} ^www.domain.com [NC,OR] 
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com [NC,OR] 
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.co.uk [NC,OR] 
RewriteCond %{SERVER_PORT} 80 [NC] 
RewriteRule (.*) https://domain.com/$1 [R=301,L] 

重定向WWW。并将域停放到正确的最终https网址。

但是如果它失败是当我进入https://www.domain.com

我瞄准在第一行的非安全网址,如何添加重定向WWW当HTTPS目前已经支持。

此外,当我添加一个子域dev.domain.com它重定向到domain.com/dev我假设因为上面的.htaccess?

谢谢

回答

1

只是将规则分成2个规则集。

#redirect all domains other than example.com to httpS://example.com 
RewriteCond %{HTTP_HOST} !^example.com 
RewriteRule (.*) https://example.com/$1 [R=301,L] 

#redirect none-secure protocol to https 
RewriteCond %{SERVER_PORT} 80 
RewriteRule (.*) https://domain.com/$1 [R=301,L] 

根据您提供的规则,子域名不应重定向。