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 the following in my Apache config:

<VirtualHost *:80>
  VirtualDocumentRoot /var/www/hosts/%0
  ServerAlias *

In /var/www/hosts, I have a directory called and one called If I go to in a browser, I get what I expect to see. Same with bill. In other words, everything is working perfectly.

However, I'm not quite satisfied with what's going on. Instead of /var/www/hosts/ and /var/www/hosts/, I'd like /home/jason/web and /home/bill/web.

How can I tell Apache to map to those subdirectories instead?

Thanks, Jason

share|improve this question
up vote 13 down vote accepted

Try this:

<VirtualHost *:80>
  #VirtualDocumentRoot /var/www/hosts/%0
  VirtualDocumentRoot /home/%1/web
  ServerAlias *

I believe that will sent requests to "" to "/home/jason/web"

The full list of VirtualDocumentRoot directives can be found here:

0     the whole name
1     the first part
2     the second part
-1    the last part
-2    the penultimate part
2+    the second and all subsequent parts
-2+   the penultimate and all preceding parts
1+ and -1+     the same as 0
share|improve this answer
That's precisely what I was after. The "%1" was the key part. Thank you. – Jason Swett Sep 20 '10 at 18:17

Could this change work?

VirtualDocumentRoot /home/%0/web

Or you may consider enabling mod_userdir, that by default would look like

share|improve this answer
That wouldn't quite get me what I want. With that solution, my directories would still have to look like this: /home/ instead of like this: /home/jason/web. – Jason Swett Sep 20 '10 at 18:15

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.