Click here to Skip to main content
11,920,641 members (52,603 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked

Using instead of http://localhost/

, 14 Oct 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
Setting up IIS and PWS so that it recognises full domain names as belonging to your machine.


Did you ever wonder if you could use instead of http://localhost/ or on your local machine? Imagine if you want to use absolute addresses in your site like 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 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
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
#          # source server
#              # x client host       localhost

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, 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 is localhost. Now change this name to any other name, such as        sameers

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 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, but you hate microsoft word and you want to access that using any other name say No problem, just get the address of the 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 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=""></a>

Note that I didn't used http://. As I got the address of my locally established domain,

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWhat if the OS is XP Pin
SameerDehalvi26-Oct-05 3:26
memberSameerDehalvi26-Oct-05 3:26 
Generalhttp://&lt;computer_name&gt; Pin
Dimitris Vassiliades7-Jul-04 10:27
memberDimitris Vassiliades7-Jul-04 10:27 
Generalpinging localhost Pin
Soliant24-Feb-03 17:58
memberSoliant24-Feb-03 17:58 
GeneralFunny and interesting Pin
Philippe Lhoste22-Oct-01 5:02
memberPhilippe Lhoste22-Oct-01 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151120.1 | Last Updated 15 Oct 2001
Article Copyright 2001 by Sameers.ME
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid