用户请求: https://www.example.com/test : https://www.example.com/test
HTTPS requests --> AWS ELB HTTPS Listener --> Apache HTTP
获取http://www.example.com/test Apache
由于DirectorySlash默认为On ,Apache将其redirect到http://www.example.com/test/ 。
用户结束HTTP请求: http://www.example.com/test/ : http://www.example.com/test/
AWS提供了HEAD来检测原始请求协议: %{HTTP:X-Forwarded-Proto} ,但是如何告诉Apache mod_dir DirectorySlash使用该头?
请在这种情况下通知您的解决scheme或解决方法。
尝试使用这个规则,这将在DirecorySlash开始之前踢入
RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [NE,R=301,L]
由于重写将在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]