Redirect www. to bare domain when using SSL
Domanda
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?
Soluzione
Ok, problem solved - I made a typical stupid mistake.
In the SSL default vhost, I listen on port 433
. Should be 443
of course.
Altri suggerimenti
Your config says that when someone enters a URL of https://groupstreamer.com/, the server should redirct them to https://groupstreamer.com/ - and you can't see the flaw here?
Lose the redirect in the 443 virtualhost. If you must use a front controller (which is wrong for so many reasons) then use the 404 handler.