1

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?

lum
  • 1,503
  • 12
  • 17
  • Also, I'd like to avoid `mod_rewrite`. Related but didn't help: http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www – lum Apr 25 '12 at 08:07

2 Answers2

2

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

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

lum
  • 1,503
  • 12
  • 17
  • 1
    Note that the certificate you're using will need to be valid for all the host names you're using (with and without `www`). – Bruno Apr 25 '12 at 10:56
  • 1
    except that what are the chances a user would enter `https://www.domain.com` ? they'll probably enter `http://www.domain.com` which will then redirect to https – Simon_Weaver Feb 08 '13 at 07:24
0

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.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • Thanks for your answer, but that's not how virtualhosts work - Apache matches the ServerName directive and uses the first virtualhost for domains that didn't match. – lum Apr 25 '12 at 08:23