htaccess 将域重定向到 https,将子域重定向到 http,将 www 重定向到非 www [英] htaccess redirect domain to https, subdomain to http and www to non-www
本文介绍了htaccess 将域重定向到 https,将子域重定向到 http,将 www 重定向到非 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试这样做:
为我的主域强制使用 https.
Force the https for my main domain.
http or https://www.domain.com -> https://domain.com
http or https://domain.com -> https://domain.com
但不适用于子域
http or https://www.subdomain.domain.com -> http://subdomain.domain.com
http or https://subdomain.domain.com -> http://subdomain.domain.com
并且总是删除 www.
And always removing the www.
现在我有了:
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
这会将 www 重定向到非 www 并将 http 重定向到 https,但不适用于子域.子域保留为 www 和 https.
This redirects www to non-www and http to https but not for subdomains. The subdomain remains with www and the https.
谢谢
推荐答案
您可以使用以下 2 条规则:
You can use these 2 rules:
# for main domain
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]
# for sub domain
RewriteCond %{HTTP_HOST} ^(www.)?subdomain.domain.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteRule ^ http://subdomain.domain.com%{REQUEST_URI} [R=301,L,NE]
这篇关于htaccess 将域重定向到 https,将子域重定向到 http,将 www 重定向到非 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文