Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 have 3 websites running off one server (one IP), each with multiple subdomains. The httpd.conf file is rather large with multiple VirtualHost tags for each subdomain. Instead of adding to httpd.conf every time I add a new site or new subdomain, I would like to have it dynamically configured. Here's the layout...

the sites are located is


so I want "" to point to


and I want to point to


How do I accomplish this in my httpd.conf file? Thanks.

share|improve this question

migrated from Oct 30 '11 at 13:49

This question came from our site for professional and enthusiast programmers.

Where would "" (no subdomain) be located in this setup? – faker Oct 30 '11 at 17:06
up vote 2 down vote accepted

If you're not looking to make the directory structure based on the owner of the site then you could easily accomplish this using the Apache2 vhost_alias module. I've used this in the past. In order to base it off the other like you are describing in your question you're going to need to do some fancy mod_rewrite writing but it likely won't be completely dynamic and require configuration to activate.

share|improve this answer

Sounds like the job for mod_vhost_alias:

share|improve this answer
Great minds think alike :) – Jeremy Bouse Oct 30 '11 at 14:41
Heh. Funny how we are spending our Sunday here. :) – Rilindo Oct 30 '11 at 14:43
I used mod_vhost_alias but it doesn't support a wildcard as a folder. The sites are, for example, /var/www/html/alec/google/www and something totally different and unrelated such as /var/www/html/somethingrandom/anothersite/admin – alecwhardy Nov 5 '11 at 5:06

There are various options included in the apache2 mass virtual host documentation. In your case a mod_rewrite solution may work for you.

share|improve this answer

Another way to accomplish this would be to use a tool like puppet to manage both the folder structure as well as the vhost files. You could easily write or even find a vhost module to accomplish this. Then you use the conf.d directory to hold all of your vhost files.

share|improve this answer

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.