【问题标题】:Redirect to HTTPS with .htaccess for several domains使用 .htaccess 为多个域重定向到 HTTPS
【发布时间】:2017-04-27 15:32:40
【问题描述】:

我有几个网站共享一个 htaccess 文件(Drupal 多站点),并希望将其中几个重定向到网站的 https 版本。我看到一个域的this solution

RewriteEngine On
RewriteCond %{HTTP_HOST} ^specific\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

我想修改它以适用于多个域,但不确定我是否可以执行以下操作,或者是否需要重新编写这些行:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^specific\.com [NC]
RewriteCond %{HTTP_HOST} ^another\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

我不想尝试,以防我炸毁几个现场网站。

【问题讨论】:

    标签: apache .htaccess ssl mod-rewrite https


    【解决方案1】:

    有两种选择:

    1. 只需重定向所有域:

      RewriteCond %{HTTPS} off
      RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
      
    2. 或使用[OR] 子句定位特定子域:

      RewriteCond %{HTTPS} off
      RewriteCond %{HTTP_HOST} ^specific\.com [NC,OR]
      RewriteCond %{HTTP_HOST} ^another\.com [NC]
      RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
      

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2018-06-02
      • 2016-02-18
      相关资源
      最近更新 更多