I have setup a load balancer which accepts https connections from users. The compute engines are then connected to load balancer using http connection.
I have written the following .htaccess file in the root folder:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Now, the problem is, the compute engine is always connected via http link (to the load balancer) and not https.
Thus, the .htaccess file always consider the connection to be http and not https even if the url starts with https. So, it goes in an infinite loop trying to send the user to https even when the url is https.
What should be done to redirect http to https in this case.
Thanks.
You should check the X-Forwarded-Proto http header. It is set by the load balancer and will have the value http or https.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With