1

I'm trying to redirect all the traffic from .se to .com but for some reason the VirtualHost ignores the ServerName and ServerAlias that I define.

<VirtualHost *:80>
    ServerName www.example.se
    ServerAlias example.se
    Redirect 301 / https://www.example.com/
</VirtualHost>

In the above example all the traffic will go through the VirtualHost redirect even though the tld is not .se

Am I missing something?

user152440
  • 113
  • 3

1 Answers1

5

Short answer: Yes.

Long answer: It sounds like this is your first VirtualHost in the configuration file, which makes this the primary virtual host. It means that your other virtual hosts aren't specific enough to match the traffic, causing them to land in this virtual host instead.

Refer to the following page: http://httpd.apache.org/docs/2.2/vhosts/name-based.html

In particular:

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

Andrew B
  • 31,858
  • 12
  • 90
  • 128
  • wow how fast to respond! and I was beginning a philosophical answer extra large :) +1 – RTOSkit Jan 08 '13 at 01:00
  • 1
    haha, I worked with httpd pretty constantly for a few years so I'm like a robot now. Maybe my avatar is a little *too* appropriate... – Andrew B Jan 08 '13 at 01:04