Some context: I'm serving a website under the domains domain.com
and alternate-domain.com
. I would like to redirect all requests so that they:
- use SSL (basically, redirect http -> https)
- use the canonical hostname
domain.com
(e.g. remove thewww
prefix)
That's what I have at the top of my apache configuration:
<VirtualHost *:80>
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:433>
Redirect permanent / https://domain.com/
SSLEngine on
# SSL Certificate directives are here.
</VirtualHost>
And then later on I have the config for https://domain.com:
<VirtualHost *:443>
ServerName domain.com
# ...
</VirtualHost>
This works as expected when I access non-HTTPS pages:
- http://www.domain.com redirects to
https://domain.com
- http://alternate-domain.com redirects to
https://domain.com
However, it doesn't work when I access domains through HTTPS. What I mean by that is that the redirection doesn't happen.
Examples:
(Note: it's normal that certificate warnings occur as they don't match the domain for which I have the certificate. All the more reason for redirecting users.)
What am I doing wrong?