Apache url 跨 aws elb 将 http 重写为 https

Apache url rewrite for http to https across aws elb

我正在尝试通过 AWS 弹性负载均衡器将我的整个域从 http 重定向到 https。

我的urlrewrite.conf (Apache/2.2.15)

RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !^on$
RewriteCond %{REQUEST_URI} ^/testdemo/
RewriteRule ^/(.*) /web/testcontroller?url= [PT]

以上规则是将主页从 http 重定向到 https。但是进入testdemo虚拟目录后得到文件“404 Not Found”

谁能告诉我这是怎么回事。

以下更改对我有用。

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

RewriteCond %{REQUEST_URI} ^/testdemo/
RewriteRule ^/(.*) /web/testcontroller?url= [PT]

移除 "RewriteCond %{HTTPS} !^on$" 条件后,事情开始按预期运行。