Skip to content

Mass virtual hosting with apache through mod_rewrite

If you are a developer and you’re working with several subdomains for development purposes, you can create a single virtualhost, without the need to add subdomains and restart/reload the apache web server.

Directory structure (example):

/var/www
/var/www/project1.unixteacher.org
/var/www/project2.unixteacher.org
/var/www/project3.unixteacher.org
/var/www/development.unixteacher.org

One single virtualhost for any subdomain:

<VirtualHost *>
 DocumentRoot /var/www
 ServerName unixteacher.org
 ServerAlias *.unixteacher.org
 CustomLog logs/access_log combined
 ErrorLog logs/error_log
 RewriteEngine On
 RewriteMap lowercase int:tolower
 RewriteRule ^/(.*)$ /var/www/${lowercase:%{SERVER_NAME}}/$1
</VirtualHost>
Published inWebservers