Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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,

share|improve this question

1 Answer 1

up vote 12 down vote accepted

untested.. but I try this

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


share|improve this answer
Yes! Thank you so much. Been struggling with this for a while now. Much appreciated. Please upvote this is answer if you find this a help. Thank you... –  rix May 4 '12 at 14:39
the link is broken –  BillR Mar 13 '13 at 17:14
Solution still works. Some explanation could be found here: docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/… –  Tim Apr 16 '13 at 7:21
Worked for me. Tested today –  Ben Sinclair Sep 23 '14 at 6:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.