Question

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:

  1. use SSL (basically, redirect http -> https)
  2. use the canonical hostname domain.com (e.g. remove the www 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:

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?

Was it helpful?

Solution

Ok, problem solved - I made a typical stupid mistake.

In the SSL default vhost, I listen on port 433. Should be 443of course.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top