从htaccess重定向排除子域。但重定向非www到www然后到https为主域

问题描述:

我是一个在htaccess领域的初学者。从htaccess重定向排除子域。但重定向非www到www然后到https为主域

我有以下规则现在

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

这可以帮助我实现以下

example.com => https://www.example.com 

但是,我需要排除的子域:

subdomain.example.com/myfile.html => http://subdomain.example.com/myfile.html 

哪有我达到了吗?

在此先感谢您的答案。 注意:我尝试了一些提供的解决方案。但他们都没有为我工作。

您可以使用HTTP =以下规则>https://www

RewriteEngine on 

RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ 
RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]