apache - Wildcards in a Windows hosts file

ID : 10121

viewed : 50

Tags : windowsapachednshostsvirtual-hostswindows

Top 5 Answer for apache - Wildcards in a Windows hosts file

vote vote


Acrylic DNS Proxy (free, open source) does the job. It creates a proxy DNS server (on your own computer) with its own hosts file. The hosts file accepts wildcards.

Download from the offical website


Configuring Acrylic DNS Proxy

To configure Acrylic DNS Proxy, install it from the above link then go to:

  1. Start
  2. Programs
  3. Acrylic DNS Proxy
  4. Config
  5. Edit Custom Hosts File (AcrylicHosts.txt)

Add the folowing lines on the end of the file:   *.localhost   *.local   *.lc 

Restart the Acrylic DNS Proxy service:

  1. Start
  2. Programs
  3. Acrilic DNS Proxy
  4. Config
  5. Restart Acrylic Service

You will also need to adjust your DNS setting in you network interface settings:

  1. Start
  2. Control Panel
  3. Network and Internet
  4. Network Connections
  5. Local Area Connection Properties
  6. TCP/IPv4

Set "Use the following DNS server address":

Preferred DNS Server: 

If you then combine this answer with jeremyasnyder's answer (using VirtualDocumentRoot) you can then automatically setup domains/virtual hosts by simply creating a directory.

vote vote


To answer your question, you cannot use wildcards in the hosts file under Windows.

However, if you want to only change the hosts file to make new sites work.... you can configure your Apache like this and you don't have to keep editing it's config:


Basically a quick summary based on my setup, add the following to your apache.conf file:

 LoadModule vhost_alias_module modules/mod_vhost_alias.so   NameVirtualHost *:80    <Directory "/xampp/sites">       Options Indexes FollowSymLinks Includes ExecCGI       AllowOverride All       Order allow,deny       Allow from all    </Directory>    <VirtualHost *:80>       VirtualDocumentRoot c:/xampp/sites/%-1/%-2+/   </VirtualHost> 

This allows me to add an entry like:       test.dev 

and then make the directory, c:\xampp\sites\dev\test and place the necessary files in there and it just works.

The other option is to use <Directory> tags in apache.conf and reference the pages from http://localhost/project/.

vote vote


I don't think that it is possible.

You anyway have to modify the apache virtualroot entries every time you add a new site and location, so it's not a big work to syncronise the new name to the Windows vhost file.

Update: please check the next answer and the comments on this answer. This answer is 6 years old and not correct anymore.

vote vote


To add to the great suggestions already here, XIP.IO is a fantastic wildcard DNS server that's publicly available.

      myproject.  -- resolves to -->   other.project.  -- resolves to -->    other.machine.  -- resolves to --> 

(The ability to specify non-loopback addresses is fantastic for testing sites on iOS devices where you cannot access a hosts file.)

If you combine this with some of the Apache configuration mentioned in other answers, you can potentially add VirtualHosts with zero setup.

vote vote


Editing the hosts file is less of a pain when you run "ipconfig /flushdns" from the windows command prompt, instead of restarting your computer.

Top 3 video Explaining apache - Wildcards in a Windows hosts file