Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.