Reputation: 111
I've got a problem with the infamous "Too many redirects" error on my website since I put an SSL certificate on with certbot.
I've been looking for hours here to find a solution to my problem, tried different solutions but none of them worked in my case.
Some background informations about the server : Debian 9 with Apache2 (both up to date)
I'm struggling with my VirtualHost files to get rid of this "too many redirect" error. There are two of them, one for non-HTTPS connections and one for HTTPS connections, both are activated in Apache of course.
Here the non-HTTPS config file (pretty simple)
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName website.com
Redirect permanent / https://www.website.com/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.website.com
Redirect permanent / https://www.website.com/
</VirtualHost>
Here is the HTTPS config file
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName website.com
Redirect permanent / https://www.website.com/
SSLCertificateFile /etc/letsencrypt/live/website.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName www.website.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/letsencrypt/live/website.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
As you notice, I want the "official" address to be "https://www.website.com" and all connection without "www." and/or "https" being redirected to this address.
Can someone help me ? Many thanks !
Upvotes: 6
Views: 13271
Reputation: 3166
I had the same issue. Had to add to my /etc/apache2/sites-available/example.com-le-ssl.conf
RequestHeader set X-Forwarded-Proto https
Hope this helps someone.
Upvotes: 1
Reputation: 1
I also found that changing the SSL level from Flexible to Full at Cloudflare fixed the problem of too many redirects when redirecting from http to https.
Upvotes: 0
Reputation: 413
I use CloudFlare and it suddenly stopped working with this error. I changed my CloudFlare SSL setting from flexible to full and that resolved the problem I was having.
Upvotes: 10
Reputation: 5051
One thing I've seen cause this is CDN and DDoS protection settings at the DNS level.
Upvotes: 0
Reputation: 111
After hours of looking in Apache2 conf, I had a look at my DNS records... It was a mess there, with some 301 redirection creating loops...
So if someone have the same issue, think about checking your domain config before spending hours on Apache config file ;)
My problem is solved !
Upvotes: 5