Click here to Skip to main content
Click here to Skip to main content

Using http://www.yourname.com 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.

Introduction

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
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       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, 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

127.0.0.1        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

127.0.0.1      www.theangrycoder.com

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

111.222.333.444     www.ibm.com

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

127.0.0.1       www.theangrycoder.com
127.0.0.1       www.hangamahouse.com
127.0.0.1       www.thelonelylover.com
127.0.0.1       www.willyouloveme.com

That's all about the HOSTS file.

License

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

Share

About the Author

Sameers.ME
Web Developer
Pakistan Pakistan
No Biography provided

Comments and Discussions

 
QuestionWhat if the OS is XP PinmemberSameerDehalvi26-Oct-05 3:26 
Generalhttp://&lt;computer_name&gt; PinmemberDimitris Vassiliades7-Jul-04 10:27 
Generalpinging localhost PinmemberSoliant24-Feb-03 17:58 
GeneralFunny and interesting PinmemberPhilippe Lhoste22-Oct-01 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web03 | 2.8.150128.1 | Last Updated 15 Oct 2001
Article Copyright 2001 by Sameers.ME
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid