Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

What I want to do is have dynamically created virtualhosts based on a username and subfolder, for example if I were to create the following folder:


The following domain will be mapped to the previous folder as its webroot

Aside from creating a script that checks for new folders, creating the matching VirtualHost in the Apache configuration, and restarting HTTPD, is there a config-friendly method of accomplishing this?

-- EDIT -- Thank you @kashani for suggesting mod_vhost_alias. It worked perfectly.

share|improve this question
up vote 3 down vote accepted

You might want to look into mod_vhost_alias.

The config in your case should look like this, though I haven't tested it.

VirtualDocumentRoot /home/%2/www/%1 

and for logging

LogFormat "%V %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"" dynamic_vhosts
CustomLog logs/access_log dynamic_vhosts

That'll put the vhost the request came into at the front of each log entry. You can adjust the rest of the setting to match what you need. If %V doesn't work, try %v. I don't believe there is a way to split out into separate log files at least with the standard Apache mod_log.

share|improve this answer
Thanks @kashani! After working with mod_vhost_alias for a while, that seemed to do the trick! My only concern now is if the project_folder directory has capital letters in it the apache usually translates as "" when in fact the directory may be "/home/username/www/EXAMPLE" – Workman Feb 3 '11 at 21:25
I can't think of a way to solve that one, but glad to hear mod_vhost_alias worked out for you. – kashani Feb 3 '11 at 21:38
One more semi-related question. Is there any way to also have virtual mapping of error and access logs using mod_vhost_alias? – Workman Feb 9 '11 at 20:24
put the logging in the answer for better formating. – kashani Feb 10 '11 at 18:47
@Workman, mod_speling might help with the case sensitivity of the folders. But I've never used it in conjunction with mod_vhost_alias: – Mat Feb 10 '11 at 19:01

With "ServerAlias *" and the Virtual User Hosts RewriteRule example, I believe you can easily setup apache to do what you wish

share|improve this answer
Can you do this with local hostnames as well? Such as (where 'dev' is the name of the machine)? – user69389 Feb 3 '11 at 18:37

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.