两个片段都将http重定向到https,但是其中一个片段适用于AWS Cloudfront分发,而另一个则不适用。单独使用,两者都可以正常工作。这两个代码段有什么区别?
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://example.com/$1 [R,L]
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
答案 0 :(得分:1)
嗯,两个之间有两个区别。
第一个块将重定向到https://example.com/ *
如果HTTPS
不是ON
如果HTTP_HOST
既不是localhost
也不是127.0.0.1
第二个块将使用https协议重定向到与请求中使用的主机相同的主机。
例如:
发件人:http://www.example.com/test?1=2&3=4
收件人:https://www.example.com/test?1=2&3=4
如果HTTPS
不是ON
或HTTP_HOST
是www.example.com
(区分大小写)。
由于它将重定向到与请求中的主机相同的主机,因此很可能会创建一个无限循环。关键区别在于您在条件中指定的[OR]
标志。