How to point any *.mydomain variation to localhost (for development)?

Posted by user41339 on Server Fault See other posts from Server Fault or by user41339
Published on 2010-04-23T18:23:33Z Indexed on 2010/04/23 18:33 UTC
Read the original article Hit count: 284

Filed under:
|

Hi all.

I am developing a site, which will make use of any given [variation of] subdomain name part (that is, the part prefixed before the host name and, optionally, the TLD part). I would imagine that in production, that would be an easy feat - make sure the DNS for second-level domain name part points to an IP, set up Apache2 virtual host to listen on that (or any) IP port 80, and just use PHP to make decisions based on the "Host" request header.

However, currently the site is localhost, since I am developing it using my workstation, so first I patched the /etc/hosts to include:

127.0.0.1 mydomain

I only used one name part (arguably a custom TLD) so as to not interfere with the Internet domain names. Then I set up a VirtualHost directive for Apache 2.2 like:

<VirtualHost *:80>
    ServerName mydomain

But now I can see that f.e. example.mydomain does not point to localhost, meaning the the /etc/hosts addition is not effective for "something.mydomain". It appears the rules are taken verbatim, and also I have checked that wildcards like *.mydomain are not allowed.

Is there a solution for this?

© Server Fault or respective owner

Related posts about apache

Related posts about virtualhosts