.htaccess HTTPS主域名&通配符HTTP子域+所有非WWW

时间:2016-06-21 04:49:40

标签: wordpress apache .htaccess mod-rewrite ssl

Stack Overflow上有许多类似的解决方案,例如htaccess http to https with www. Without redirecting sub domain

然而,我需要的是:

  • 主域名HTTPS + NON-WWW
  • 所有子域的通配符HTTP,而不是一个接一个地添加。

我正在运行WordPress Multisite网站,并且没有通配符SSL。

我现在正在使用以下内容:

非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}

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

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]