【问题标题】:HTTPS for www and non-www only - HTTP for all subdomains仅适用于 www 和非 www 的 HTTPS - 适用于所有子域的 HTTP
【发布时间】:2015-08-18 21:34:31
【问题描述】:
我只有单个域的证书,包括 www。
使用我当前的 .htaccess 设置,我将所有 HTTP 请求重定向到 HTTPS。
但我想使它如下:
- 强制 HTTPS domain.com(www 和非 www)
- 仅允许所有子域 *.domain.com 使用 HTTP
这可能吗?
我当前的 .htaccess 设置强制一切使用 HTTPS
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
【问题讨论】:
标签:
apache
.htaccess
http
mod-rewrite
https
【解决方案1】:
我找到了 1 个解决方案:
# Force HTTPS www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# Force HTTP subdomains
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]