繁体   English   中英

如何防止子域重定向到https-htaccess?

[英]How to prevent subdomains from redirecting to https - htaccess?

我试图弄清楚如何将所有http实例重定向到https://,但不包括子域。

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

例如, domain.example.co应该保留原样,并且不要重定向到https://

example.coexample.co/sub/sub应该重定向到https://

我试过更改RewriteRule:

RewriteRule ^$ https://example.co/$1 [R,L]

这样就保留了子域,但对example.co下的子目录没有影响-即example.co/sub/sub。

如何从http重定向到https,但排除所有子域?

注意

我也有一个重写规则,该规则将子域指向其目录,而无需更改URL:

RewriteCond %{HTTP_HOST} ^(.*)\.example\.co [NC]
RewriteRule ^(.*)/?$ http://example.co/%1/$1 [P]

sub.example.co将显示example.co/sub但网址不会更改

您可以尝试以下方法:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} ^(.+\.)?domain\.com$
RewriteRule ^(.*)$ https://%1domain.com/$1 [R,L]

或这个 :

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$
RewriteRule ^(.*)$ https://sub.domain.com/$1 [R,L]

注意:将sub替换为subdomain,将domain替​​换为domain name

好好享受 ;-)

请尝试以下操作,我假设您没有使用附加到主机的www。

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^example.co [NC]
RewriteRule ^(.*)$ https://example.co/$1 [L,R=301,QSA]

RewriteCond %{HTTP_HOST} ^(.*)\.example\.co [NC]
RewriteRule ^(.*)/?$ http://example.co/%1/$1 [P]
ProxyPassReverse / http://example.co/

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM