Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many redirects with SSL - Apache

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 !

like image 408
Zemou Avatar asked Dec 19 '22 01:12

Zemou


1 Answers

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.

like image 162
naps1saps Avatar answered Jan 13 '23 23:01

naps1saps