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 a website on localhost, mapped in HOSTS as:

However, the folder (C:/www/vhosts/ has some sub-folders in it, namely:




and rather than typing in

I would like to try and have the URL as:

I've had a look for how to do this on Google, but am not quite sure how to do this.

I tried the advice here - Automatic subdomain creation in htaccess on Apache - and it did work (good if I only have a few folders) but what if I have multiple ones? I don't want to keep adding them to it, so I've been trying to find a solution.

What's the best way to achieve this?

share|improve this question

You'll want to create a new VirtualHost which will serve up the subdomains dynamically based on the directory tree:

<VirtualHost *:80>
    ServerAlias *
    VirtualDocumentRoot "C:/www/vhosts/"
    ... (logging, permissions, etc) ...

The %1 uses the first block of the name, so will point to C:/www/vhosts/

More info on the VirtualDocumentRoot directive can be found here.

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.