Apache with mixed HTTP only and HTTPS virtualhosts
Of course redirecting from https to http is possible with:
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
SSLEngine on
# All other SSL settings, just like in your working TLS VirtualHost.
Redirect / http://www.example.com/
</VirtualHost>
You just have to understand that:
- This will first give a warning "Your connection is not private", because the hostname in HTTP
Host:
header doesn't match the your certificate, i.e.NET::ERR_CERT_COMMON_NAME_INVALID
. Of course this is something you already get. - Normal users don't write
http://
orhttps://
in the address bar, just thewww.example.com
, which gets by default completed withhttp://
. (Actually, some users don't even know about the address bar, but uses Google search instead, then picking the first result.)
I'd rather create a catch-all virtualhost with some default page explaining that there is no TLS
site configured for this domain. Make sure this comes before the working virtualhost by using a filename that gets first on apache2/sites-enabled
, like 001-tls
, and use <VirtualHost _default_:443>
.