Apache DirectorySlash 将 HTTPS 请求重定向回 HTTP

sta*_*chx 8 http https redirect apache-2.2 amazon-elb

用户请求: https://www.example.com/test

HTTPS requests --> AWS ELB HTTPS Listener --> Apache HTTP

阿帕奇获取 http://www.example.com/test

http://www.example.com/test/由于默认情况下DirectorySlash 处于开启状态,Apache 将其重定向到。

用户以 HTTP 请求结束: http://www.example.com/test/

AWS 提供了一个 HEAD 来检测原始请求协议:%{HTTP:X-Forwarded-Proto},但是我如何告诉 Apache mod_dir DirectorySlash 使用该标头?

在这种情况下,请告知您的解决方案或解决方法。

sta*_*chx 6

由于重写将在 DirectorySlash 之前启动,以下是最终结果并且它有效:

# Redirect to HTTPS before Apache mod_dir DirectorySlash redirect to HTTP
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteCond %{LA-U:REQUEST_FILENAME} -d
RewriteRule ^/(.*[^/])$ https://%{HTTP_HOST}/$1/ [R=301,L,QSA]
Run Code Online (Sandbox Code Playgroud)