.htaccess将单个域重定向到https,而不是重定向的所有域(别名)

.htaccess将单个域重定向到https,而不是重定向的所有域(别名),.htaccess,redirect,https,.htaccess,Redirect,Https,我让example.com和alias sub.example.com指向同一个目录。我希望所有重定向到,但保持sub.example.com为非ssl 以下是我尝试的内容,但它并没有将example.com重定向到https: RewriteCond %{HTTPS} off RewriteRule ^(http:\/\/example\.com.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 我做错了什么?重写规则与域名不匹配。对于这种情况

我让example.com和alias sub.example.com指向同一个目录。我希望所有重定向到,但保持sub.example.com为非ssl

以下是我尝试的内容,但它并没有将example.com重定向到https:

RewriteCond %{HTTPS} off
RewriteRule ^(http:\/\/example\.com.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我做错了什么?

重写规则与域名不匹配。对于这种情况,您需要使用
RewriteCond

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

重写规则
与域名不匹配。对于这种情况,您需要使用
RewriteCond

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