Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 这两段代码之间有什么区别?_Amazon Web Services_Redirect_Mod Rewrite_Https_Amazon Cloudfront - Fatal编程技术网

Amazon web services 这两段代码之间有什么区别?

Amazon web services 这两段代码之间有什么区别?,amazon-web-services,redirect,mod-rewrite,https,amazon-cloudfront,Amazon Web Services,Redirect,Mod Rewrite,Https,Amazon Cloudfront,这两个代码段都将http重定向到https,但其中一个适用于AWS cloudfront发行版,而另一个不适用。就其本身而言,这两种方法都很好。这两段代码之间有什么区别 RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1) RewriteRule ^/(.*) https://example.com/$1 [R,L] 好吧,这两个之

这两个代码段都将http重定向到https,但其中一个适用于AWS cloudfront发行版,而另一个不适用。就其本身而言,这两种方法都很好。这两段代码之间有什么区别

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    RewriteRule ^/(.*) https://example.com/$1 [R,L] 

好吧,这两个之间有一些不同

第一个块将重定向到*

如果
HTTPS
未启用
如果
HTTP\u 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
不在
上,或者
HTTP\u主机
www.example.com
(案例生效)

由于它将重定向到与来自请求的主机相同的主机,因此很可能会创建一个无限循环。关键区别在于您的条件中指定的
[或]
标志

RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]