I want to setup my local development machine so that any requests for *.local
are redirected to localhost
. The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local
, site2.local
etc, and have them all resolve to localhost
, while Apache serves a different site accordingly.
I am on Windows XP.
I tried adding
127.0.0.1 *.local
to my c:\windows\system32\drivers\etc\hosts
file, also tried:
127.0.0.1 .local
Neither of which seem to work.
I know I can set them up on different port numbers, but that is a pain since it is hard to remember which port is which.
I don't want to have to setup a local DNS server or anything hard, any suggestions?
Source: Tips4all, CCNA FINAL EXAM
I don't think that it is possible.
ReplyDeleteYou 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.
To answer your question, you cannot use wildcards in the hosts file under Windows.
ReplyDeleteHowever, 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:
http://postpostmodern.com/instructional/a-smarter-mamp/
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:
127.0.0.1 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/.
I found a posting about Using the Windows Hosts File that also says "No wildcards are allowed."
ReplyDeleteIn the past, I have just added the additional entries to the hosts file, because (as previously said), it's not that much extra work when you already are editing the apache config file.
Editing the hosts file is less of a pain when you run "ipconfig /flushdns" from the windows command prompt, instead of restarting your computer.
ReplyDeleteAcrylic 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.
ReplyDeletehttp://mayakron.altervista.org/support/browse.php?path=Acrylic&name=Home
You could talk your network administrator into setting up a domain for you (say 'evilpuppetmaster.hell') and having the wildcard there so that everything (*.evilpuppetmaster.hell') resolves to your IP
ReplyDeleteI could not find a prohibition in writing, but by convention, the Windows hosts file closely follows the UNIX hosts file, and you cannot put wildcard hostname references into that file.
ReplyDeleteIf you read the man page, it says:
DESCRIPTION
The hosts file contains information regarding the known hosts on the net-
work. For each host a single line should be present with the following
information:
Internet address
Official host name
Aliases
Although it does say,
Host names may contain any printable character other than a field delim-
iter, newline, or comment character.
that is not true from a practical level.
Basically, the code that looks at the /etc/hosts file does not support a wildcard entry.
The workaround is to create all the entries in advance, maybe use a script to put a couple hundred entries at once.
Have apache listen on many ports is also an alternative.
ReplyDeleteI have written a simple dns proxy in Python. It will read wildcard entries in /etc/hosts. See here: http://code.google.com/p/marlon-tools/source/browse/tools/dnsproxy/dnsproxy.py
ReplyDeleteI have tested in Linux & Mac OS X, but not yet in Windows.
You may try AngryHosts, which provided a way to support wildcard and regular expression. Actually, it's a hosts file enhancement and management software.
ReplyDeleteMore features can be seen @ http://angryhosts.com/features/
Following on from @Stu Thompsons answer, please feel free to use my domain anySubDomain.reconn.co.uk. This will point any sub domain to your local host 127.0.0.1. I will leave this up and running if it is of any use.
ReplyDeleteA workaround that works if you're online...
You can also use different directories on the same virtual host:
ReplyDeletehttp://localhost/site1
http://localhost/site2
http://localhost/site3
http://localhost/site4
and so on... Using <Directory ...> directives to configure each in a different way if necessary