Skip to main content

Wildcards in a hosts file


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: Tips4allCCNA FINAL EXAM

Comments

  1. 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.

    ReplyDelete
  2. 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:

    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/.

    ReplyDelete
  3. I found a posting about Using the Windows Hosts File that also says "No wildcards are allowed."

    In 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.

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

    ReplyDelete
  5. 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.

    http://mayakron.altervista.org/support/browse.php?path=Acrylic&name=Home

    ReplyDelete
  6. 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

    ReplyDelete
  7. I 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.

    If 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.

    ReplyDelete
  8. Have apache listen on many ports is also an alternative.

    ReplyDelete
  9. I 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

    I have tested in Linux & Mac OS X, but not yet in Windows.

    ReplyDelete
  10. You may try AngryHosts, which provided a way to support wildcard and regular expression. Actually, it's a hosts file enhancement and management software.
    More features can be seen @ http://angryhosts.com/features/

    ReplyDelete
  11. 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.

    A workaround that works if you're online...

    ReplyDelete
  12. You can also use different directories on the same virtual host:

    http://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

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex