I have got a strange problem.

I have two domains: mysite.co.uk and mysite.com, which need to point to the same directory on my server. The VHost for mysite.co.uk works perfectly. However, mysite.com will not work.

When I re-start apache I see no errors. When I enter the domain, it is reaching the correct server but showing me the index file in /var/www, instead of re-directing to /var/www/html/mysite.co.uk/web/

Is there an error with my code? It is EXACTLY the same as what appears on the configuration for mysite.co.uk, so I am very confused as to why it is not working properly.

Sites Available:

<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /var/www/html/mysite.co.uk/web/
ServerAlias *mysite.com


<VirtualHost *:80>
ServerName *.mysite.com
DocumentRoot "/var/www/html/mysite.co.uk/web/"

You should be able to do this with a single vhost entry as long as the content you want displayed on both URL's is in the same folder on the server.

<VirtualHost *:80>
ServerName mysite.com
ServerAlias mysite.co.uk *.mysite.co.uk *.mysite.com
DocumentRoot /var/www/html/mysite.co.uk/web/

You may also be getting betrayed by a default vhost if you have setup your new ones in a seperate file.

If your running Ubuntu (Or some other distro's) you can use 'apache2ctl -D DUMP_VHOSTS' from the command line to show what ServerNames are being accepted and what config file:line they are in.

Note - this does not list address added on ServerAlias lines


I don't think you should be using wildcards in your second ServerName directive (in Apache.conf), try replacing it with www for the moment, while leaving the wildcard aliases in Sites Available, if you have more than one mysite.com subdomain the server will respond to.

  • Ok, I just tried that but no luck. What logs should I be looking at for any potential errors? – Bob Flemming May 14 '13 at 9:57
  • Can you change one more thing? I think the ServerAlias in Sites Available should probably be *.mysite.com, you may not see errors, as it isn't wrong, just not right for what you want.. – NickW May 14 '13 at 10:06
  • Ok I have got it working on www.mysite.com. I was having an issue with test.mysite.com, but I have changed the mx record of www.mysite.com to point at the new server and the vHost seems to work. However, test.mysite.com is still not working so I guess its a subdomain issue? - Apologies for not mentioning that in my question – Bob Flemming May 14 '13 at 10:22
  • It may be a DNS issue, you need to make sure that test is either a CNAME or an A record, and that record now points to the new server. – NickW May 14 '13 at 10:26
  • 1
    First try and add the ServerAlias directive to apache.conf also, possibly both with just test.example.com, just to ensure the Alias matches exactly.. – NickW May 14 '13 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.