I am using Apache, and would like to redirect all subdomain and non www addresses to the www version using Virtual Hosts.
The only exception to this rule is that I want media.domain.com to point to the same location as www.domain.com because I want a different, cookieless domain for images and video to be located on.. (speed).
The code below is not however working. How would one go about achieving this?
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias www.domain.com media.domain.com
ServerAdmin [email protected]
DocumentRoot /srv/www/domain.com
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com
ServerAlias domain.com
Redirect permanent / http://www.domain.com/
</VirtualHost>
There are a couple of ways of doing this depending on if this is the only domain on the server or not.
You can use a wildcard in the ServerAlias to do a catch all on a domain like below
If this is the only domain on the server then you can use a default vhost
in both cases the default or wildcard will match unless there is a more specific vhost.
In response to the comment can you try.