Tuesday, April 7, 2009

Using Separate Host or Domain Names for Website Development on Windows with IIS or Apache Using Hosts File

Whether you run IIS or Apache you can run local sites similar to 'localhost'.

When you type localhost in your browser's address bar and hit enter, the address always translates to the loopback IP address in IPv4, or ::1 in IPv6.

You can easily create similar names which will always translate to loopback IP address or point to any specific IP address of your choice.

Here is what you have to do:

1. Press Windows key + R, the Run... dialog box will appear. - If your keyboard lacks the Windows key, you may click Windows Start button and then click on Run... option in the Start menu.

2. Type drivers and hit enter, the Windows explorer will appear.

3. Now browse to drivers/etc/

4. Open the host file with Notepad application.

You'll see at least on entry inside your host file. Almost all host file contain the following entry: localhost

To add another entry, change your host file in this way: localhost local.com

Save your hosts file.

Try loading local.com from your browser, do NOT add www. You will see that you are hiting Apache or IIS on your own computer.

Now, reopen host file and add one more entry: localhost local.com www.local.com

Save the file and try to load the new URL www.local.com from your browser and you continue to hit your local web server.

Another shot: localhost local.com www.local.com www.yahoo.com

Save the file and now you can NEVER access the real Yahoo but will see the localhost site from your web server.

Another important aspect: localhost local.com www.local.com www.yahoo.com www.ebay.com

Save your hosts file. Now whenever you will type www.ebay.com on your browser you will be taken to the webserver running on your network computer that has the given IP address of

Bingo, you're ready for the next tutorial on configuring Apache and IIS to serve or show different content when different domain names are passed.

Don't jump into conclusions and remeber that: 1. This will not change the settings of your websites users or anything outside your computer. 2. Just because you added ebay.com to your host file doesn't make you owner of that domain name. 3. Nobody else can visit your site by typing local.com and until they specifically update their hosts file 4. Don't try to hack into someone else's computer using this concept since you will be caught just too easily and it will be foolish to spend dozens of years in jail for such a simple hack. If you want to serve jail time then it better be some serious hack.

☛ Quick Links

♥ Recommended For You