How to Edit Your Hosts File – Test Your New Website Before Going Live

On Windows XP/2003/Vista/7 this file is located in:

%SystemRoot%\system32\drivers\etc\
(Typically C:\Windows\System32\drivers\etc)

With Vista/Windows 7 you will need to edit this file with administrative privileges.  You can do this by following one of these two sets of intructions:

  1. Click on the Windows logo.
  2. Search for ‘notepad’
  3. Right click on the notepad launcher and select ‘Run As Administrator’
  4. Click File, then Open
  5. Browse to the folder mentioned above and select the hosts file

Alternatively in Windows 7 copy  %SystemRoot%\system32\drivers\etc\ and paste the text into the search box (see step 1 above). Right click the hosts file and choose “Open File Location” and edit as above.

 

Note: While the hosts file edits are in place you will not be able to visit your active site from your computer. You will either need to remove the edits, work with 2 hosts files or just use another computer.

 

Why would you want to do this? This is useful when moving websites to a new host.  This would allow you to recreate your site at the new host and browse to it as though it’s live.

Example:

Here is a typical Hosts file

# Copyright (c) 1993-2009 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

 

# localhost name resolution is handled within DNS itself.

#             127.0.0.1       localhost

#             ::1             localhost

 

To modify the hosts file to point to your test site simply add a line with your new servers ip followed by a space with your sites domain

23.67.19.45  mycoolsite.com www.mycoolsite.com