I have multiple virtual hosts on my server, let's say I serve
www.example.com
sub.example.com
www.example.nl
In my DNS config, all points to the same server.
In apache2 config, there's a default config-file for http and one for https, and additional vhosts for the additional sites. I want all near-matches to be redirected to www.example.com
. All specific sites have a certificate.
So my files look like this
000-default.conf (redirects to https://www.example.com)
default-ssl.conf (serves https://www.example.com)
sub.example.com.conf (redirects to https://sub.example.com)
sub.example.com-ssl.conf (serves https://sub.example.com)
www.example.nl.conf (redirects to https://www.example.nl)
www.example.nl-ssl.conf (serves https://www.example.nl)
The problem is now that any other request (say, for be-creative.example.nl
) defaults to the first loaded configuration. This works for http (000-default
will match and redirect), but it does not work for https, because I have no valid certificate loaded for be-creative.example.nl
. Therefore I cannot redirect, nor serve a valid page.
If I disable default-ssl.conf
, the request is matched by sub.example.com-ssl.conf
and the wrong certificate is served still.
Question: How can I handle these requests for which I have no certificate elegantly? How can I redirect to http without first having a valid matching certificate?