Here is my config file
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Redirect permanent / https://www.mywebsite.co/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And when I type in the browser mywebsite.co it successfully redirects me https://mywebsite.co however content does NOT render on the page because of this error (by Google Chrome)
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
I have an EC2 instance using port 80 to handle http requests and a load balancer handling https requests. I am not sure what to do and none of the solutions I've found online are working.
The reason you see the “too many redirects” error is because your website has been set up in a way that keeps redirecting it between different web addresses. When your browser tries to load your site, it goes back and forth between those web addresses in a way that will never complete — a redirect loop.
You are requesting via SSL over port 443 when you hit the ELB, but then you are requesting to the backend as insecure port 80. This is fine, but then your config has no idea that this is supposed to be over 443 because you are reverse proxying it. To the web server, this is just a port 80 insecure request, so it will try to redirect to SSL port 443, which is why it's looping.
Instead of doing a redirect, you might look at a rewrite to analyze the forwarded headers, e.g.:
RewriteEngine On
RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
RewriteRule ^(.*)$ https://www.mywebsite.co$1 [R=301,NE,L]
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