【问题标题】:How to write htaccess for subdomain redirection to https如何编写 htaccess 以将子域重定向到 https
【发布时间】:2014-01-17 09:43:40
【问题描述】:

如何编写将 example.com 重定向到 www.example.com 的 htaccess 规则,而且我们有许多子域,例如 subdomain.example.cpm,所以我需要将其重定向到 https://subdomain.example.com。但是当我编写 htaccess 规则时,它会循环。请发送如何为此编写条件。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    # example.com to www.example.com
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    # http to https for subdomains
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    

    【讨论】:

      猜你喜欢
      • 2019-07-09
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 2015-05-19
      • 2019-03-03
      • 1970-01-01
      • 2012-06-03
      • 2017-04-22
      相关资源
      最近更新 更多