I run an apache server behind an https portal and have an issue with directory redirection. My apache server is a docker container that receives requests forwarded by an https portal container (steveltn/https-portal). Everything works fine, except the default http redirections that are made to http instead of https. For instance, let say we have a directory named test in my apache website. Calling https://example.com/test returns a 301 code with redirection to http://example.com/test/. The right behaviour would be to have a redirection to https.
I first thought it was a misconfiguration of my https portal, and asked steveltn/https-portal team. But they replied it's a problem in my apache configuration (https://github.com/SteveLTN/https-portal/issues/67#issuecomment-257934618). The summary of the answer is
PORTAL does tell the Apache about its existence by the request header X-Forwarded-Proto: https. Some web apps recognize this header automatically, such as WordPress. I guess now it up to you to configure your web app to recognize this header
I tried a lot of configuration found on the Internet for instance this one, but none fixes the problem:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
If I change the RewriteCond to %{HTTP:X-Forwarded-Proto} https, I get a infinite redirection loop.
Any idea ?