简体   繁体   English

如何使 htaccess 强制 https 用于 www.example.com 和 example.com 但没有其他子域

[英]how to make htaccess force https for www.example.com and example.com but no other subdomains

I have a host that has many subdomains and I want to force https (redirect for https ) for www.example.com and example.com but not any other subdomain, how to do this? I have a host that has many subdomains and I want to force https (redirect for https ) for www.example.com and example.com but not any other subdomain, how to do this?

currently I am using:目前我正在使用:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

but this does not work as expected但这并没有按预期工作

You can just add a condition using HTTP_HOST :您可以使用HTTP_HOST添加条件:

RewriteCond %{HTTPS} !=on
RewriteCond HTTP_HOST ^(?:www\.)?example\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com) - htaccess redirect https://www. (https://www.example.com) to non www (https://example.com) 强制从 https://example.com 重定向到 https://www.example.com - force redirection from https://example.com to https://www.example.com 解析 http://www.example.com 以通过 htaccess 永久重定向到 https://example.com - Resolving http://www.example.com to permanently redirect to https://example.com via htaccess 如何将https://example.com/重定向到https://www.example.com/ - How to Redirect https://example.com/ to https://www.example.com/ 如何将 https://www.example.com/aaa 重定向到 https://example.com/aaa/ - how to redirect https://www.example.com/aaa to https://example.com/aaa/ 将* .example.com和example.com重定向到HTTPS的www.example.com时出现问题 - Problem with redirecting *.example.com & example.com to www.example.com for HTTPS 如何将 http://www.example.com 重定向到 https://example.Z4D236D9A2D102C5ZFE6AD1Cware - How to redirect http://www.example.com to https://example.com with middleware www.example.com和example.com-> this.example.com的.htaccess重写规则 - .htaccess rewrite rules for www.example.com and example.com -> this.example.com Apache2 使用虚拟主机将 https://example.com 重定向到 https://www.example.com - Apache2 redirect https://example.com to https://www.example.com with vhosts httpd.conf将https://example.com重写为https://www.example.com - httpd.conf rewrite https://example.com to https://www.example.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM