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 know it's possible to setup this system using a code of code, and a lot of pain-in-the-butt to maintain virtual hosts, but is there a dynamic way where it checks to be sure the folders exist?

I'd like to setup a system where on a site the default URL would be and it would look for public_html/live/, but if I set it would look to public_html/dev/, BUT if I setup it would look for public_html/dev/ and it would use the LIVE database.

I'd like it to be setup so I only have to create a new directory within public_html in order to create a new subdomain, but still be able to maintain the ability to add -[INSERT_DB]

share|improve this question

You should be able to use mod_vhost_alias to get the arbitrary virtual hosts working with something like this:

UseCanonicalName Off
VirtualDocumentRoot /home/username/public_html/%1

I'm not sure how you intend on getting Apache to select the database, but you might be able to do that with mod_rewrite and setting DocumentRoot.

share|improve this answer

Create a new virtualhost for your dev site. Something like:

<VirtualHost *>
        ServerAlias dev*    
        DocumentRoot /my/path/public_html/dev/

That will route both and to the same place.

Since you also want to switch the databases dynamically, you will also need to change your application code to be smart enough to look at the incoming URL and use the correct database. You probably don't want to do that at the Apache level (just my opinion).

share|improve this answer
With this setup I would still need to have an entry for each repository, is there a way for me to make even this part dynamic, so that whatever I put in "dev" it'll look for that repo, if it's not found, it'll split by - and search for the first part of the split to see if that repo exists? – Webnet Aug 10 '11 at 12:03

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.