How to configure local apache to support multiple local dev sites using wildcard subdomains?

Wednesday, July 2, 2014

I have many web projects under

[/var/www/personal]$ ls
project1 project2 app1 app2 hello index.php

I want visit these projects by access:

and when I visit it goes to /var/www/personal/index.php

So far I've added this to my hosts:

and enabled vhost_alias mod in apache config, and here's my virtual host configurations:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias *
VirtualDocumentRoot /var/www/personal/%1
<Directory /var/www/personal/>
AllowOverride All
Order allow,deny
allow from all

LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ combined

But it doesn't work. I have two questions:

1) Can I get it work without adding every sub domain into my hosts file?

2) I can get the subdomains work if I add every sub domain into my hosts file, but what should I do to make point to index.php ?