对于无限级别的子域,我负担不起通配符SSL证书,我只有一个*.domain.tld通配符。因此,我希望HTTPS请求被重写到HTTP请求,如果在%{HTTP_HOST}变量中有多个级别的子域。如果没有或有一个子域,则应该将HTTP请求重写为HTTPS请求。
例如:
www.domain.tld -> 1 subdomain(s) HTTPS
domain.tld -> 0 subdomain(s) HTTPS
sub.domain.tld -> 1 subdomain(s) HTTPS
two.sub.domains.tld -> 2 subdomain(s) HTTP
a.b.c.domain.tld -> 3 subdomain(s) HTTP这是我能想到的唯一不涉及购买通配符证书的解决方案。
发布于 2015-12-29 12:49:49
您可以使用:
RewriteEngine on
# redirect http to https with 0 or 1 subdomain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^([^.]+\.){1,2}[^.]+$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# redirect https to http with 2 or more subdomains
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^([^.]+\.){3,}[^.]+$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 您无法避免https重定向的SSL安全错误消息。
https://stackoverflow.com/questions/34511059
复制相似问题