我要:
- 将“domain.com”规范化为“www.domain.com”
- 启用 SSL,但是:
- 从/PHP/* 中排除 SSL
- 从特定页面“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/