簡體   English   中英

通過htaccess將所有流量重定向到https://www.domain.com

[英]redirect all trafic to https://www.domain.com via htaccess

我的ssl適用於https://www.domain.com而不是https://domain.com所以我想將https://domain.com重定向到https://www.domain.com

我使用了我在這里找到的關於如何編輯htaccess以將所有流量定向到安全域的解決方案:

#Http to https
#Exclude subdomains
RewriteCond %{HTTP_HOST} !^(sub1|sub2)
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NC,L,R]
#add www on ssl
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

但是,這不適用於以下重定向:

https://domain.comhttps://www.domain.com

這里有什么問題,如何解決?

試試:

RewriteEngine on


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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM