6

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 !

5 Answers 5

10

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.

5

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 !

2
  • 4
    For users of CloudFlare check if SSL is set too "full"
    – runefist
    Commented Jun 11, 2018 at 14:37
  • @runefist You're my savior! Thanks! Commented Jan 12, 2020 at 14:26
1

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.

0

One thing I've seen cause this is CDN and DDoS protection settings at the DNS level.

2
  • can you elaborate on the CDN part ? Commented Sep 10, 2018 at 2:59
  • having a CDN or DDoS set up (or any sort of mirroring, etc) can cause redirect loop issues or SSL conflicts because what you assume is pointing at an IP is probably actually pointed at something else. this is an issue with things like CloudFlare DNS. the OP confirmed this by saying their DNS was misconfigured.
    – nrutas
    Commented Sep 12, 2018 at 9:36
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.