November 2025
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930

Categories

November 2025
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930

SSL redirect on EC2 instance behind SSL terminating load balancer

Question

I’m trying to redirect all url’s to https in a web application.

I have an ec2 instance behind an elastic load balancer. SSL is terminated on the load balancer.

Any attempts at redirection end up giving me the familiar ‘this page is requesting in a way which will never complete’.

The load balancer forwards 443 and 80 to port 80 on the instance.

This is what I have in my .htaccess.

RewriteCond %{X-FORWARDED-PROTO} !=on 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Does anyone have any idea how to accomplish this? Kind thanks,

 

Answer

untested.. but I try this

RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>