大网数据广告活动
服务器运维问答

Apache DirectorySlash redirects HTTPS requests back to HTTP

· 52CE 我爱测

User Request: https://www.example.com/test HTTPS requests --> AWS ELB HTTPS Listener --> Apache HTTP Apache getting http://www.example.com/test Apache redirect it to http://www.example.com/test/ due to DirectorySlash is On by def…

问题原文

原帖链接 · starchx · CC BY-SA 3.0

User Request: https://www.example.com/test

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

Apache getting http://www.example.com/test

Apache redirect it to http://www.example.com/test/ due to DirectorySlash is On by default.

User ends up with a HTTP request: http://www.example.com/test/

AWS provides a HEAD to detect origin request protocol: %{HTTP:X-Forwarded-Proto}, but how do I tell Apache mod_dir DirectorySlash to use that Header?

Please advise your solution or workaround in this scenario.

已采纳解答

原帖链接 · starchx · CC BY-SA 3.0

Since rewrite will kick in before DirectorySlash, here is what ended up with and it works:

# 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]

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。