简体   繁体   English

如果没有子域名,htaccess强制https并将非www重定向到www

[英]htaccess force https and redirect non www to www if not have a subdomain

I am trying to force https and redirect non-www to www: 我试图强制https并将非www重定向到www:

The problem is I have many sudomains and I don't have wildcard ssl (for now) so I want : 问题是我有很多sudomains,我没有通配符ssl(现在)所以我想:

  • (x).domain.com (except www.domain.com) ===> http://*.domain.com (x).domain.com(www.domain.com除外)===> http://*.domain.com

Is that possible ? 那可能吗 ?

All the ansewers i found and tested only force https or redirect all non-www to www my problem is i don't want subdomains get https except for www and redirect non-www to www 我发现和测试的所有ansewers只强制https或重定向所有非www到我的问题是我不希望子域名获取https除了www和重定向非www到www

To force https://www only for the www.example.com , you can use : 要仅为www.example.com强制使用https:// www ,您可以使用:

RewriteEngine on
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

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

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