.htaccess - 如何启用 SSL 排除特定目录和排除子域

标签 .htaccess ssl subdomain

我要:

  1. 将“domain.com”规范化为“www.domain.com”
  2. 启用 SSL,但是:
  3. 从/PHP/* 中排除 SSL
  4. 从特定页面“noSSL.htm”中排除 SSL

这是我的:

#enable SSL excluding /PHP directory
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule !^php/.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#Enable SSL and add "www." if missing
RewriteEngine On
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

问题/问题:

  • 问题:子域获取 SSL
  • 如何从 SSL 中排除特定文件?
  • 我需要重复“RewriteEngine On”吗?

非常感谢任何帮助!

最佳答案

根据您的评论,规则应如下所示:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{SERVER_PORT} !=443
RewriteRule !^(php/.*|.*noSSL\.htm)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^  http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

因此 noSSL.htm 将被排除。

注意:清除浏览器缓存然后测试。

关于.htaccess - 如何启用 SSL 排除特定目录和排除子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731444/

相关文章:

android - .htaccess HTTP_USER_AGENT 不起作用

php - 通过公共(public)互联网安全发送数据的替代方法

SSL 证书过期

asp.net - 如何在 IIS 7 上设置子域

subdomain - 子域是否应该作为子文件夹进行访问?

subdomain - 在子域中存储客户端文件(img、css、javascript)有什么好处?

wordpress - URL 重写不适用于一个 URL

apache - IndexIgnore *或选项-Indexes

ssl - 最近无法通过 HTTPS 连接到我的 NAS

php - .htaccess 将 php 重写为 php 文件