【问题标题】:Redirect specific sub domains to https in .htaccess with mod_rewrite使用 mod_rewrite 将特定子域重定向到 .htaccess 中的 https
【发布时间】:2017-02-28 18:12:23
【问题描述】:

我正在尝试从 TEST 环境开始在我的服务器上测试 SSL。这些规则似乎适用于我的本地,但是当我提交到我的测试服务器时,我收到“重定向过多”错误。

以下是我拥有的相关重写条件/规则:

# Send non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Send test.mysite.com to https
RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(.+)\.test\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.test\.mysite\.com$ [NC]
RewriteRule ^ https://www.test.mysite.com%{REQUEST_URI} [L,R=301]

目标是将 www.test.mysite.com 和 test.mysite.com 都发送到https://www.test.mysite.com

【问题讨论】:

  • 那些规则对我来说看起来不错...也许其他一些规则会干扰这里?真实服务器配置或其他动态配置文件中的规则(意外)将 back 重定向到 http?
  • 如果你找不到任何东西,那么我建议你启用重写日志(参见重写模块的官方文档)。它允许您检查重写引擎内部实际发生的每个步骤。

标签: apache .htaccess redirect mod-rewrite


【解决方案1】:

我已取消注释该行:

RewriteCond %{HTTP_HOST} ^(.+)\.test\.mysite\.com$ [NC]

它现在似乎可以在私人浏览器中运行。这是否使 www 行变得不必要了?

RewriteCond %{HTTP_HOST} ^www\.test\.mysite\.com$ [NC]

【讨论】:

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