【问题标题】:.htaccess HTTPS Main Domain & Wildcard HTTP Sub-Domains + All Non-WWW.htaccess HTTPS 主域和通配符 HTTP 子域 + 所有非 WWW
【发布时间】:2016-10-22 11:50:13
【问题描述】:

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

然而,我需要的是:

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

我正在运行一个 WordPress 多站点网站并且没有通配符 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}

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite ssl


    【解决方案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]
    

    【讨论】:

    • 嗨弗洛里安,谢谢!不,不幸的是它不起作用。在我添加它的那一刻,即使删除了 WWW,一切都会转到 HTTPS。
    • 我忘记在上面的评论中标记你了。
    猜你喜欢
    • 2018-08-10
    • 2015-07-18
    • 2017-04-22
    • 2019-01-23
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    相关资源
    最近更新 更多