簡體   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