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

I have some odd situation. I wan to make different DirectoryRoot for one domain.

example.com -> /dir1 www.example.com -> /dir1

*.example.com -> /dir2

I'm trying settings with NameVirtualHost and ServerAlias. Could you help?

share|improve this question

1 Answer 1

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/dir1

<VirtualHost *:80>
  ServerName other.example.com
  ServerAlias *.example.com
  DocumentRoot /var/www/dir2

The order is important - the 'www' vHost must precede the wildcard.

See: http://stackoverflow.com/questions/758351/virtualhost-for-wildcard-subdomain-and-static-subdomain

share|improve this answer
<VirtualHost *:80> DocumentRoot = /var/www/wildcard ServerName other.example.com ServerAlias *.example.com <VirtualHost> This is not working. It is only forking for other.example.com. When I'm browsking to aaaa.example.com is is loading content form /var/www/example not from /var/www/wildcard –  Petter Jul 7 '11 at 8:32
The equal signs should not have been present - I have edited the example above, hopefully it work for you. –  cyberx86 Jul 7 '11 at 8:47

Your Answer


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.