How to forward URLs from HTTP to HTTPS when using AWS ALB
Application Load Balancer (ALB) has been introduced in Amazon Web Services.
This ALB has a function to remove SSL from HTTP requests from outside and change the communication between ALB and web server to HTTP communication, but due to this effect, whether the communication between ALB and client is HTTP or HTTPS, it looks like HTTP communication to the web server. Therefore, you need to be aware of ALB. Therefore, if the configuration is not ALB-aware, you will end up in a redirection loop.
Example that works properly through ALB
The second line is for direct requests without going through ALB, and the third line is for access through ALB. :// URL.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC].
RewriteRule ^(. *)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]