https://subdomain.example.com重定向到https://example.com:port

时间:2011-10-14 10:14:06

标签: mod-rewrite ssl https

最近为我们的主域名和www.domain购买了SSL证书。不是通配符证书。

我有重写规则,重定向所有http://subdomain.example.com - > https://example.com:port

但是,当我直接键入https:/subdomain.example.com时,它会显示“不受信任的连接”消息。有没有办法让它不这样做呢?

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteEngine On

# redirect all www (http or https) to https://domain.com  
RewriteCond %{HTTP_HOST} ^www.domain.com [nc]
RewriteRule (.*) https://domain.com:80/$1 [R=301,L]

# redirect http://domain.com to https://domain.com
RewriteCond %{HTTP_HOST} ^domain.com [nc]
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://domain.com:80/$1 [R=301,L]

# redirect all sub domain (http or https) to https://domain.com
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.domain\.com$  [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule (.*) https://domain.com:80/$1 [R=301,L]