仅限 www 和非 www 的 HTTPS - 所有子域的 HTTP
HTTPS for www and non-www only - HTTP for all subdomains
我只有单个域的证书,包括 www.
使用我当前的 .htaccess 设置,我将所有 HTTP 请求重定向到 HTTPS。
但我想让它遵循:
- 强制 HTTPS domain.com(www 和非 www)
- 仅允许所有子域使用 HTTP *。domain.com
这可能吗?
我当前的 .htaccess 设置强制一切都使用 HTTPS
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我找到了 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]
我只有单个域的证书,包括 www. 使用我当前的 .htaccess 设置,我将所有 HTTP 请求重定向到 HTTPS。 但我想让它遵循:
- 强制 HTTPS domain.com(www 和非 www)
- 仅允许所有子域使用 HTTP *。domain.com
这可能吗?
我当前的 .htaccess 设置强制一切都使用 HTTPS
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我找到了 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]