SSL redirect on EC2 instance behind SSL terminating load balancer

6,579

untested.. but I try this

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

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-proto

Share:
6,579

Related videos on Youtube

rix
Author by

rix

Updated on September 18, 2022

Comments

  • rix
    rix over 1 year

    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,

  • rix
    rix about 12 years
    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...
  • Bill Rosmus
    Bill Rosmus about 11 years
    the link is broken
  • Tim
    Tim about 11 years
    Solution still works. Some explanation could be found here: docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGui‌​de/…
  • Ben Sinclair
    Ben Sinclair over 9 years
    Worked for me. Tested today