htaccess将域名重定向到https,将子域名重定向到https,将非www重定向到www [英] htaccess redirect domain to https, subdomain to https and non-www to www
本文介绍了htaccess将域名重定向到https,将子域名重定向到https,将非www重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样做:
为我的主域强制使用https。
Force the https for my main domain.
http到 https:// www 。
http:// www 到 https:// www 。
但不适用于子域
http://subdomain.domain.com 到 https://subdomain.domain.com
有人可以帮我吗?
推荐答案
您可以在根目录 .htaccess
中使用它:
You can use that in your root .htaccess
:
RewriteEngine on
# redirect to https www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteEngine on
# redirect no-www to www only main domain, not with subdomain
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect http to https all domain
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
这篇关于htaccess将域名重定向到https,将子域名重定向到https,将非www重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文