Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I recently got my domain name working fine with my server and managed to get subdomains pointing to specific folders. However I have just noticed a little problem. I have my /etc/apache2/sites-enabled/000-default set to:

<VirtualHost *:80>
        VirtualDocumentRoot /local/www/%1
        ServerName *.dev.localhost
</VirtualHost>

and when I go to test.dev.mydomain.co.uk it displays the content of /local/www/test/ and that's great. However, I mistyped the domain and realise that test.mydomain.co.uk is also doing the exact same thing when you miss out the .dev.part. I don't want this to happen. Can anybody suggest any fixes?

share|improve this question

2 Answers 2

If...

  • The VirtualHost block above is the first one in your configuration, and
  • There is no explicit match for, e.g., test.mydomain.co.uk

...then Apache will use the above VirtualHost block for test.mydomain.co.uk. That is, in the absence of an explicit match, Apache will use the first VirtualHost definition it finds. From the documentation:

If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.

share|improve this answer
    
But I do have another VirtualHost block directly above it yet it's not taking that one on. –  andy Aug 13 '12 at 12:39
    
Well, then this probably isn't the problem. What does the previous VirtualHost block look like? –  larsks Aug 13 '12 at 12:42
    
It's one that makes vps.mydomain.co.uk point to /local/www/static –  andy Aug 13 '12 at 12:47
up vote 0 down vote accepted

Solved the question:

<VirtualHost *:80>
    VirtualDocumentRoot /local/www/%1
    ServerName dev.mydomain.co.uk
    ServerAlias dev.mydomain.co.uk *.dev.mydomain.co.uk
</VirtualHost>

By using ServerAlias.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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