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

In my Apache (Xampp) httpd-vhosts.conf file I have added this Virtualhost It allows me to use Wildcard names like and I just have to make sure to add the name to my Windows Hosts file.

<VirtualHost *:80>
  VirtualDocumentRoot  E:/Server/htdocs/projects/%1/www
  ServerAlias *.dev

What I would like to do though is add to this funtionality and make it work if the name begins with a www so would also work as

The way it currently is set up, if I tried to access that URL, it would look in a folder called www.testserver1 instead of the folder testserver1

share|improve this question
up vote 3 down vote accepted

Get rid of the ServerAlias and change the %1 to %-2.

<VirtualHost *:80>
  VirtualDocumentRoot  E:/Server/htdocs/projects/%-2/www

As explained in the Directory Name Interpolation section of the mod_vhost_alias documentation, the %-2 will tell Apache to look at the second from the last part of the name.

The next section in the linked document has examples, one of which is the following:

VirtualDocumentRoot "/usr/local/apache/vhosts/%-2.0.%-1.0"

Which will allow as well as or to serve files from /usr/local/apache/vhosts/ It does this as follows:

%-2.0  # The second from the last part of the name with a zero-length substring.
       # The .0 is necessary as we need to specify a literal period next and don't
       # want the parser to confuse it with a substring specification.

.      # a literal period

%-1.0  # the last part of the name with a zero-length substring. The .0 should be
       # optional here as there's nothing left to cause confusion, but it doesn't
       # hurt anything to have it.
share|improve this answer
Great thanks, I should note I had to keep using ServerAlias otherwise it would just route to my servers root – JasonDavis Sep 26 '12 at 1:33

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.