Super User is a question and answer site for computer enthusiasts and power users. 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 following structure of my web projects on my hard drive in /var/workspace/www/

firstdomain_com
 \- www
 \- anysubdomain
seconddomain_com
 \- dev
 \- api
 \- www

I need to run all these applications on my local machine (and be able to use .htaccess properly) so I need to setup my /etc/hosts and /etc/apache2/sites-enabled/*:

/etc/hosts

::1     ip6-localhost ip6-loopback www_firstdomain_com.local 

anysubdomain_firstdomain_com.local

/etc/apache2/sites-enabled/*

<VirtualHost www_firstdomain_com.local:80>
    DocumentRoot /var/workspace/www/firstdomain_com/www
    ...
</VirtualHost>
<VirtualHost anysubdomain_firstdomain_com.local:80>
    DocumentRoot /var/workspace/www/firstdomain_com/anysubdomain
    ...
</VirtualHost>

In case of much (sub)domains it seems to be boring and ineffective.

It is possible to set both Apache & /etc/hosts to be able to handle requests like this automatically without manual writing each of these hosts into /etc/hosts and apache conf separately? Is there any way to set some kind of "wildcard" or regex into both config files?

share|improve this question
up vote 2 down vote accepted

Apache covers this itself under the topic Dynamically configured mass virtual hosting found at:
http://httpd.apache.org/docs/2.2/vhosts/mass.html

Sadly you can't use wildcards in /etc/hosts though. Personally I use a local named (DNS server) on my machines so I can easily play with local zones for purposes like this.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .