VirtualHost ignores ServerName and ServerAlias

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?


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.