When you are developing and using a local development environment, you typically need to hit your own site. A lot. You'd use URLs that look like this:
When you get slightly more advanced, you would want to run multiple sites off your installation. You can easily do this with name based virtual hosts (eg. with
Those URLs don't work, so now we need to find some way to map our domain names to the "localhost" address.
What if we could map hostnames to 127.0.0.1 and make this work?
The first and easiest method is where one edits their hosts file (
At work, we have up to five different hostnames for each of our clients. Adding yet another client means dozens of developers that now need to edit their hosts file. Oh, the pain and agony when you have to do this for hundreds of domains!
What if we could have a single top-level domain that always resolved to localhost?
If you are using Windows DNS, you can create a new zone:
On Linux systems, you can install dnsmasq to pretend to be a real DNS server and actually respond with 127.0.0.1 for all subdomains of a top level domain. So, if you wanted *.local to always resolve to your own domain, then you can use URLs like this:
You only need to install and set up dnsmasq. There's some well-written instructions at http://drhevans.com/blog/posts/106-wildcard-subdomains-of-localhost that you can follow; I won't repeat them here.
The drawback of this setup is that you now have to install and configure dnsmasq on every machine where you want to use this trick.
What if someone set up DNS entries and basically did this for you?
It turns out that some kind hearted people already set up wildcarded domains for you already. You can use any top level domain below and any subdomain of these and they will always resolve back to 127.0.0.1 (your local machine). Here's the list of ones I know about. Let me know if there are more!
Now, with these wildcarded domains, you don't need to do any modification of your system for requests to come back to your own server. For instance, you can go to http://client1.127-0-0-1.co.uk/ and the web page request will always head back to your own server. You'll still need to configure your web server to answer on this hostname, but at least the DNS portion of the problem is now solved.
Programmer Tips >