Did you ever wonder if you could use http://www.yourdomainname.com instead of http://localhost/ or http://127.0.0.1/ on your local machine? Imagine if you want to use absolute addresses in your site like http://www.mydomainname.com/myfolder/myfile.asp. What do you need to do? You have to connect to the internet and after updating your file, you have to upload that and then test on the server. But if you have a technique which allows you to use an absolute address on your own system without connecting to the internet then why you use that lengthy procedure?
The real question is: How can I tell my IIS or PWS that http://www.mydomainname.com is pointing to the files on my local computer and hence, do not try to access the internet?
The answer of the question is behind another question. Did you ever wonder why in each system where IIS or PWS is installed, http://localhost/ works? The only answer is that surely there must be any entry of localhost in the IIS or PWS. That's nice and enough to move further because if localhost is written somewhere in your computer, then obviously, you can change that to any word you like.
The location of the entry of localhost depends on the operating system you have. If you are using Windows 98, that is somewhere else and if you are using Windows NT or 2000, that is at another place. But the file where the entry exists is the same. The file name is HOSTS. Note that this file does not have any extension. If you are using windows 98, go to your windows folder, like c:\windows\ and look for this file (HOSTS). If you found that, open it using any text editor like notepad (If it does not exist, create it yourself). But if you are using windows NT or Windows 2000, it will be <windows-directory>\System32\Drivers\etc\ where <windows-directory> is the folder in which your windows installed (it is winnt/ by default).
Nice, we have accessed to the file and the contents of the file may look like this.
# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# 18.104.22.168 rhino.acme.com # source server
# 22.214.171.124 x.acme.com # x client host
Wow, we have got the localhost entry. OK change it with the text you want. But wait a minute, you can read this file to get more clear view of this file and it's usage.
The lines starting with # are comments and this file is designed by Microsoft as mentioned at the top of this file. Other lines tell that the files manipulates the IP addresses and their targets. As you know, 127.0.0.1 is always the address of local computer. Only the last entry of this file will work because it is not commented. The last line simply tells that the nick name or the alternative name of the 127.0.0.1 is localhost. Now change this name to any other name, such as
Then I will be able to access my local site using http://sameers/ if I am running PWS or IIS. OR I can change this entry to
I always access my site using http://www.theangrycoder.com That's nice and enough to work. Now I can use absolute paths in my sites and they will not generate any missing link error when I try to access them.
You can use this file in more advance mode. Like, you knows the IP address of a site say Microsoft.com, but you hate microsoft word and you want to access that using any other name say www.ibm.com. No problem, just get the address of the microsoft.com site and open your file and make an entry here. Say, microsoft's site has the IP address 111.222.333.444 then you can write in this file
Now type in your browser http://www.ibm.com and the microsoft will be there. Note that you can use ping utility to get the IP address of any site. Go to command prompt and type
ping <a href="http://www.anysitename.com">www.anysitename.com</a>
Note that I didn't used http://. As I got the address of my locally established domain, www.theangrycoder.com
So you can get the IP address of any site using same utility. I used it under windows 2000 but you can also use under windows 98. The first try using http:// before site names generated an error but without http://, it was fine.
Finally, it is not that you can use only one entry in this file. You can make as many entries as you want. It means, if you are working on the multiple sites, you can make multiple entries here. like
That's all about the HOSTS file.