为什么.htaccess会忽略“ [NC]上的RewriteCond%{HTTPS}!”?

时间:2019-05-23 04:19:52

标签: apache .htaccess https

由于我声明仅当它不是“ https://”请求时才应重定向,因此如果我键入“ https://example.com/index.rd1.html”,则此代码不应从index.rd1.html重定向到index.rd2.html。在网址中,但确实如此。为什么?

RewriteEngine On
RewriteCond %{HTTPS} !on [NC]
RewriteCond %{REQUEST_URI} index.rd1.html [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/index.rd2.html [R=301,L]

1 个答案:

答案 0 :(得分:0)

事实证明,hostway.com(托管网站)没有标准的.htaccess规则。为了使其能够检测到https,我必须在HTTPS之前添加“ ENV:”,如下所示:

RewriteCond %{ENV:HTTPS} !=on