I have a apache2 serving an application which works fine on www.domain.co.uk but when going to domain.co.uk (non www) it doesn't redirect the traffic. I added a redirect to my .conf file and it still doesn't work. See below:
<VirtualHost *:80>
ServerName domain.co.uk
Redirect permanent / http://www.domain.co.uk/
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain.co.uk
ServerAlias domain.co.uk
# Actual server configuration
</VirtualHost>
Does anyone know how to redirect the non-www traffic to www (or fix my configuration!)?
You have two separate areas of the configuration capturing domain.co.uk - one is in the redirection, the other (through your use of ServerAlias) in the configuration that serves the content. The second capture is overriding the first.
To resolve the issue, simply remove the line:
ServerAlias domain.co.uk
and restart Apache.