Redirect too many times after autolly configuration in apache2

My domain is: https://tianyi.codes

I ran this command: certbot --apache

It produced this output: a file named 000-default-le-ssl.conf

My web server is (include version): apache 2.4.29

The operating system my web server runs on is (include version): Ubuntu 18.04 LTS

My hosting provider, if applicable, is: alicloud

I can login to a root shell on my machine (yes or no, or I don’t know): yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): XShell6

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): 0.31.0

Im noooooob.
this might be a dumb question.
so after running certbot --apache, I got an error “redirect too many times” when I go to my site.
I fixed it by comment out the redirect line in 000-default-le-ssl.conf.
Since it is a configuration file for :443 port, which stands for an HTTPS request, the thing that makes me curious is why is there a redirect to https url? In what case is that gonna be used?
Thanks for your time!!

1 Like

Perhaps you already got such a redirect and perhaps certbot added another one, so you ended up with too much redirect statements? Without actually seeing the specific configuration statements, it’s hard to say.

2 Likes

Hi @TianyiTimothy

checking your domain there is only one correct redirect - https://check-your-website.server-daten.de/?q=tianyi.codes

Domainname Http-Status redirect Sec. G
http://tianyi.codes/ 47.88.14.185 301 https://tianyi.codes/ Html is minified: 100,00 % 0.343 A
https://tianyi.codes/ 47.88.14.185 GZip used - 3530 / 15403 - 77,08 % Inline-JavaScript (∑/total): 5/0 Inline-CSS (∑/total): 0/0 200 Html is minified: 141,83 % 5.660 I

So your current configuration works.

You can remove the comment, then recheck your domain to see, where you have a loop:

http -> https -> http
https -> https
http -> http

A typical problem non-www -> www -> non-www isn’t possible because your www version isn’t defined.

3 Likes
<VirtualHost *:443>
    <Directory /var/www/TianyiTimothy.github.io>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/TianyiTimothy.github.io

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        Redirect "/" "https://tianyi.codes/"

Hi, @JuergenAuer and @Osiris,
Thanks for your reply!!
Here is my configuration, so the last line Redirect "/" "https://tianyi.codes/" is what caused the problem.
I removed the comment and checked my link. The website says “Error direct loop”.
I think it could be https->https loop if that’s possible.
Thanks again for your reply!

2 Likes

certbot doesn’t use those kind of redirects (it uses mod_rewrite), so I guess the redirect was already in place in your HTTP configuration and certbot just copied it when it made the HTTPS virtualhost. It probably assumes no such redirect is already in place.

2 Likes

A general redirect in the port 443 part is always wrong - that’s the loop listet there - https://check-your-website.server-daten.de/?q=tianyi.codes - https -> https.

Looks like you have defined that redirect in the http part, then certbot used that as template to create the https part.

3 Likes

Hi dear @Osiris, @JuergenAuer
Thanks so much for your reply!!
Best wishes

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.