Redirect from http to https issue

Hi guys,

I have the problem that my redirect from http to https is not working. If i go to mydomain.de my site isnt available. If i go direct to https://mydomain.de everything is working like charm.

in my sites-available I have the following files: 000-default.conf, 000-default-le-ssl.conf, nextcloud.conf and mydomain.de.conf

The first two files I added the following in the end: <Directory /var/www/html/> Options +FollowSymlinks AllowOverride All </Directory>
In the mydomain.de.conf I have <VirtualHost *:80> ServerName mydomain.de Redirect permanent / https://mydomain.de/nextcloud </VirtualHost

In my sites-enable there is one file as well: 000-default-le-ssl.conf
Any Idea where to search for the problem? I dont know what to google anymore… :smiley: Maybe there is a .htaccess making a problem?

Thanks a lot!

Try to use the following as only content of 000-default.conf:

<VirtualHost *:80> 
ServerName mydomain.de
Redirect permanent / https://mydomain.de/
</VirtualHost>

The 000-default-le-ssl.conf can contain the document root, location directive etc, all within the <VirtualHost *:443> directive. And assure of course that both ports 80 and 443 are open/forwarded and journalctl -u apache2 (and/or /var/www/apache2/error.log) do not contain any errors.

okay I try that. Actually there is a lot more in that file:

<VirtualHost *:80>
    # 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/html

    # 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

RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

<Directory /var/www/html/>
Options +FollowSymlinks
AllowOverride All

The error.log file does not show any unusual :slight_smile:

Edit: sadly it makes no difference to replace the file content

RewriteEngine on

Ah this rewrite part is what certbot installs to force http -> https redirection. It is actually an overhead compared to “simple” redirect, but in your case it even doubles which might cause the issue. Try to remove the rewrite part (3 lines) and keep the redirect only, or the other way round.

Also you restarted apache2 after doing the change? systemctl restart apache2

Oh yes thank you!! Removing the rewrite part made it working! Yay!
Yes of course I restarted after the changes. Do I understand it correctly that certbot is adding that part? If so, I will get a problem the next time certbot is renewing the certificate?

agree

Redirect permanent / https://mydomain.de/

is the best redirect