How to Fix Laravel HTTPS Redirect Loop on Amazon Elastic Beanstalk/Load Balancer/Proxy

If you are forcing HTTPS on routes in Laravel but are having issues with a redirect loop and your app is behind a proxy, load balancer, or something like Elastic Beanstalk, try adding this to your .htaccess file:

#Fixes HTTPS Redirect Loop

Many load balancers will accept HTTPS traffic and forward it internally as HTTP but pass an environment variable stating that the traffic received at the load balancer/proxy was intended for HTTPs. What this line does is checks for that environment variable X-FORWARDED-PROTO and if it is set to HTTPS remaps the request to HTTPS behind the proxy or load balancer.