.htaccess HTTPS主域和通配符HTTP子域+所有非WWW [英] .htaccess HTTPS Main Domain & Wildcard HTTP Sub-Domains + All Non-WWW
本文介绍了.htaccess HTTPS主域和通配符HTTP子域+所有非WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在堆栈溢出方面有许多类似的解决方案,例如 htaccess http到带有www的https。无需重定向子域。
There are many similar solutions on Stack Overflow such as htaccess http to https with www. Without redirecting sub domain.
不过,我需要的是:
- 主域HTTPS +非万维网
- 所有子域的通配符HTTP,而不是一个接一个地添加。
我正在运行WordPress Multisite网站,并且没有通配符SSL。
I am running a WordPress Multisite website and have no wildcard SSL.
目前,我正在使用以下内容:
I am using the following at the moment:
非WWW
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
非WWW和非HTTPS子域
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=subdomain1.main.com
RewriteCond %{HTTP_HOST} !=subdomain2.main.com
RewriteCond %{HTTP_HOST} !=subdomain3.main.com
RewriteCond %{HTTP_HOST} !=subdomain4.main.com
SSL
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
推荐答案
这是您想要的吗?
RewriteEngine On
RewriteBase /
# www is redirected to base domain
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# base domain should use HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
# other domain should use HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
这篇关于.htaccess HTTPS主域和通配符HTTP子域+所有非WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文