1

I have several domains for a website that is running on a digitalocan droplet:

my-domain.de
mydomain.de
my-domain.com
mydomain.com

I also installed a letsencrypt ssl certificate.

My goal is that the domain https://www.my-domain.de is my main domain and all other versions redirect permanently to this one.

What works: When i enter some of the non https domains (http://mydomain.de) the redirect works well and the browser shows https://www.my-domain.de.

What not works yet: When i enter a https domain (https://mydomain.de) there is no redirect and the browser shows a certificate warning like "the page is not secure".

This is my virtual host configuration:

# my-domain.de.conf
<VirtualHost *:80>
    ServerName www.my-domain.de
    ServerAlias my-domain.de
    ServerAlias www.mydomain.de
    ServerAlias mydomain.de

    ServerAlias www.my-domain.com
    ServerAlias my-domain.com

    ServerAlias www.mydomain.com
    ServerAlias mydomain.com

    Redirect permanent / https://www.my-domain.de
</VirtualHost>
# my-domain.de-le-ssl.conf
<IfModule mod_ssl.c>

<VirtualHost *:443>
    ServerAdmin admin@my-domain.de
    ServerName www.my-domain.de

    DocumentRoot /var/www/domain/release/public

    <Directory /var/www/domain/release/public/>
        ...
    </Directory>

    ...

    SSLEngine On
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/www.my-domain.de/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.my-domain.de/privkey.pem
</VirtualHost>

The problem is that I am not able to define a redirect rule for the https pages. When I try do define a new VirtualHost 443 Block for the redirection from https://mydomain.de to https://www.my-domain.de the whole page is down and not reachable. What do I have to do fix this redirect issue?

igi
  • 125
  • 1
  • 15
  • You can't have ServerAliases with different domains as you will only serve one certificate for a specific domain. As soon as the certificate CommonName is different from the domain you reached, you'll get an invalid certificate error. You need to create one vhost per domain. – Capsule May 23 '19 at 05:04
  • Ok, you are right. I created a vhost block for each domain. But it is still not working. All port 80 domains redirect correcty to the main domain https://www.domain.de but the other port 443 ports do always show the 'wrong certificate name' error. But now i think it is a normal behavior. Many 'big sites' have the same 'problem' (examples: https://www.planetwissen.de https://www.planetsports.com https://www.tonline.de https://www.wallstreetonline.de). The certificate check occurs before the redirect. – igi May 23 '19 at 21:21
  • sorry if I was not clear enough but you'll need to add the correct domain certificates for all the redirecting vhosts too. If you run certbot-auto again it should detect your new vhosts and allow you to create the new certificates. – Capsule May 26 '19 at 23:11

0 Answers0