Mass Virtual Host using VirtualDocumentRoot

Recently I required to update my development environment such that I can quickly setup virtual hosts, without needing to update the httpd.conf file everytime. It turns out that Apache supports a directive called VirtualDocumentRoot which allows you the map your host directories based on the domain name.
I wanted to setup domains like project-name.user-name.devserver.name, hence following is the settings I used to get that setup. So using the following configuration domain name I can use is secret.rp.mydevserver.com and the code for it is located at /websites/rp/secret/web assuming I am using symfony (hence the web directory)

ServerAdmin rajat_pandit@ipcmedia.com
CustomLog /var/log/apache2/dynamic.log cookie
ErrorLog /var/log/apache2/dynamic.error.log
RewriteLogLevel 0
RewriteLog /var/log/apache2/dynamic.rewrite.log

DocumentRoot /websites
UseCanonicalName off

VirtualDocumentRoot /websites/%2/%1/web
AllowOverride All

RewriteEngine On

More details can be found at http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html#examples

About rp

Architect for large, highly scalable LAMP applications and Technical Manager with special focus on metrics based continuous improvement of teams and products. Rajat has close to a decade of experience of a very wide range of skills related to infrastructure, middleware, app servers all the way to front-end technologies and software development methodologies including agile, iterative waterfall, waterfall as well as ah-hoc startup using the right approach in the right context to reduce time to market.