Apache htaccessforcehttps&;www.ondomain&;子域上没有http

Apache htaccessforcehttps&;www.ondomain&;子域上没有http,apache,.htaccess,mod-rewrite,subdomain,no-www,Apache,.htaccess,Mod Rewrite,Subdomain,No Www,我如何在htaccess中获得域上的https和www,以及子域上的http no www 以下内容将重定向到 您可以使用: # for main domains RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.domain.com%{REQUEST_UR

我如何在htaccess中获得域上的https和www,以及子域上的http no www

以下内容将重定向到

您可以使用:

# for main domains
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L,NE]

您需要在清除浏览器缓存后对此进行测试。

!你救了人类的命,不让外星人攻击!非常感谢。
# for main domains
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L,NE]