Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache HTTP:X-Forwarded-Proto in .htaccess is causing redirect loop in dev environment

I've had to update my .htaccess from this:

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

to this:

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

to get it working behind an AWS Elasic Load Balancer.

It all seems to work fine on AWS, but in my local environment I'm stuck in a redirect loop.

How I can get this setup to work correctly in both environments?

like image 205
greg Avatar asked Oct 29 '14 00:10

greg


1 Answers

To make it work in both environments you can combine both conditions:

RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
like image 174
anubhava Avatar answered Sep 18 '22 12:09

anubhava