Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to offer custom subdomains for my customers. I can add virtual host configuration for each subdomain but it gets a overwhelming job as the number of users increase.

What I currently use is like this:

NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot /var/www/mysite/user1
<VirtualHost *:80>
  DocumentRoot /var/www/mysite/user2
<VirtualHost *:80>
  DocumentRoot /var/www/mysite

Is there a better way of configuring subdomains?

Is it possible to make a simple check and direct an non-existing virtual host to the main site?

PS: Some other Virtualhosts still need to be defined this way.

share|improve this question


Within your VirtualHost definition:

VirtualDocumentRoot /var/www/multipledomains_root/%0

Then anything that comes at the HTTP_HOST header apache will try to match in %0

Look at ( to have a complete list of what you can do.

share|improve this answer
does it work along with regular VirtualHost configuration – mustafa Mar 27 '13 at 18:05
yes, and you should if you have multiple rules for subdomain hosting. – Marcel Mar 27 '13 at 18:19

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.