Staging and previewing a site
Posted by Wolf Leonhardt on 22 April 2015 06:18 PM

Very often clients want to build a site while leaving the original site intact while the new site is being put together.

This then leads to the problem of how to preview  a site using the normal URL (ie  You can put in a alias for example but in some cases (think wordpress) this causes an issue when you try to go live with the site.

Fortunately there is a trick that you can do so that even though you are building a staging site, you can see it as if it is a live site.

Before I explain the trick, we need to understand how going to website works.

When you type in the website name (for example the web browser will use the "dns" (domain name servers) to resolve (figure out) the IP address of the web site you wan to go to. ( in our example resolves to  BUT what if I wanted to build a new site and it is on a different IP (for example

So here is the trick, almost all modern operating systems check a local (on your machine) file before querying (asking) the "dns" servers.  That file is called a hosts file and anything we put in there will be used instead of the "dns" query.  If I wanted just my machine to go to the new staging site, I would enter the IP and the web address in that file.
Here is an example of what that might look like:

 # 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:
#          # source server
#              # x client host

# localhost name resolution is handled within DNS itself.
#       localhost# ::1             localhost      #so this entry points to the ip ending in 77 instead of the "live" 78 address

So how do we edit the hosts file?  We are going to use notepad for that.  First thing we need to do is make sure we open notepad as an administrator.  This can be done by finding it in our menu (depending on what version of windows you have) and "right clicking it".  This should allow you to select the option to "run as administrator".   So once notepad is open in the correct manner we navigate to windows\system32\drivers\etc  .  Now when you do that you might not see the hosts file and that is because notepad automatically tries to show only txt files.  All you need to do here is use the drop down (lower right hand corner) and change the selection from "text documents"  to "all files".

Once you have made changes to the hosts file, there is one more thing to be aware of.  On many systems the file extensions (ie  .txt) are not visible, so you need to make sure the hosts file you save is not accidentally saved as hosts.txt (your changes won't work).  The trick there  is to again when saving , select "all files" and not the default txt file.

On a MAC system you would launch Terminal  then type in sudo nano /private/etc/hosts.   The remainder of the process is similar to the windows method.

(0 vote(s))
Not helpful