1

I have multiple domains, but I have only one certificate. I have created two virtualhost's, one with certificate for domain: domain.lt second with redirects to domain.lt

Apache's SSL config:

<IfModule mod_ssl.c>

    <VirtualHost *:443>
        <Directory "/var/www/html">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>

        ServerName domain.lt
        ServerAlias www.domain.lt     
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/domain.lt/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.lt/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        <Directory "/var/www/html/main/wp-content/uploads/">
            Options -Indexes
        </Directory>
    </VirtualHost>

    <VirtualHost *:443>
        <Directory "/var/www/html">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>

        ServerName domain.pk
        ServerAlias www.domain.pk
        ServerAlias domain.fi
        ServerAlias www.domain.fi
        ServerAlias domain.eu
        ServerAlias www.domain.eu
        ServerAlias domain.hk
        ServerAlias www.domain.hk
        ServerAlias domain.ae
        ServerAlias www.domain.ae

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

        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^(www.)?domain.(pk|fi|eu|hk|ae)$
        RewriteRule ^(.*)$ https://domain.lt%{REQUEST_URI} [L,R=301]
    </VirtualHost>

</IfModule>

But I'm still getting warnings in browser that the connection is not secure and the certificate is only for domain.lt. After adding exception in browser I'm being redirected. How can i accomplish that?

Nisse Engström
  • 208
  • 2
  • 5

1 Answers1

3

The TLS(SSL) part of the connection happens before the HTTP part of the request.

This means that you MUST present a valid certificate for the domain the browser is requesting BEFORE you can send an HTTP 302/etc redirect. All of the HTTP winds up wrapped up in the TLS encryption.

Otherwise the end user browsers will show warnings that will need to be bypassed (not best practice).

Daniel Widrick
  • 3,488
  • 2
  • 13
  • 27