【问题标题】:How to enforce https for all directories except a few inside the parent directory for adon domains如何对所有目录强制执行 https,除了 adon 域的父目录中的少数目录
【发布时间】:2014-11-25 03:01:06
【问题描述】:

我有一个 public_html,我想强制执行 https,但不包括此文件夹中的某些目录,因为这些文件夹是父目录,其中包含其他未安装 SSL 的域的文件。

我用它来为整个 public_html 强制执行 https

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但我想排除一些目录,但以下不起作用。

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^site2 [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

谢谢。

【问题讨论】:

  • REQUEST_URI 总是以斜杠开头:RewriteCond %{REQUEST_URI} ^/site2 [NC] 表示if uri begins with site2...
  • 只是添加到之前的评论中,您并没有排除 site2,而是将 site2 设置为使用 HTTPS,而其他所有 uri 都会关闭 HTTPS。

标签: apache .htaccess http https


【解决方案1】:

可能最简单的方法是将规则基于请求所针对的域,例如

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} yourSecure.domain  [NC,OR]
RewriteCond %{HTTP_HOST} yourOtherSecure.domain  [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【讨论】:

    猜你喜欢
    • 2013-07-12
    • 2012-08-27
    • 1970-01-01
    • 2020-10-02
    • 2023-03-03
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    相关资源
    最近更新 更多