How to use the HOSTS file for website previews

Using a hosts file entry on your laptop or computer allows you to force your browser to a specific web server, this is helpful when you are waiting for dns updates on a domain name to complete or your have recently transferred or registered a domain name,

Using your HOSTS file for website previews.

  • If you are not using your actual domain name in the website URL certain website features may not work correctly.
  • Wordpress websites may force a rewrite on the domain name URL so it may not display or may point back to the previous host. 
  • Visiting the site via HTTPS will only work with the exact domain name.

To test your website with your own domain name (temporary URL) before DNS propagation has completed, you can use your local computer's HOSTS file. Your computer will read this HOSTS file before it looks up the DNS for your domain. Below you will find instructions for editing the HOSTS file on Windows Apple's Mac OS X.

Windows.

  1. Locate the HOSTS file on your computer. This is usually located in C:\windows\system32\drivers\etc\hosts
  2. Open this file with a text editor such as Notepad++ or Notepad
  3. Open the file, you will see two columns of information, the first containing IP addresses and the second containing host names. By default, a windows hosts file should be similar to the following:

    Filename: hosts
    127.0.0.1 localhost

  4. You can add additional lines to this file that will point requests for a particular domain to your new server's IP address. Example:

    Filename: hosts
    127.0.0.1 localhost
    50.321.123.80 example.com
    50.321.123.80 www.example.com

  5. Save your changes.
  6. Restart any currently open browsers.
  7. You may also want to flush your DNS cache. To do this go to Start, and then Run, then type "cmd" and hit enter. Type the following:

    ipconfig /flushdns
  8. Visit your new site using http://example.com or http://www.example.com/


Mac OS X.

  1. In Applications, open Terminal, then the Utilities folder.
  2. Type the following command to edit your hosts file:
    sudo vi /private/etc/hosts

  3. When prompted, enter your user password.
  4. You will see a file with contents similar to the following:

    Filename: hosts
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost
    Add your domain and IP address to the bottom of the file. For example:
    Filename: hosts
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost
    50.321.123.80 example.com
    50.321.123.80 www.example.com

  5. Press "i" to enter "insert mode" so you can edit the file.
  6. Press "Esc" to exit "insert mode" when you are done modifying the file.
  7. Type ":wq" to save and quit.
  8. Restart any currently open browsers.

Visit your new site using http://example.com/ or http://www.example.com/

  • HOSTS file, temp URL, website preview, preview website, test url
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How to change name servers on a domain name

This guide will assist you with changing the name servers (DNS Servers) associated with your...

What Name Servers Do I use when Registering or Transferring a Domain

When registering a domain name or transferring a domain name via the Absolute Hosting store, you...

Change WHOIS Registrant contact information for a domain name

This guide will walk you through the steps required to change the Registrant information is...

How to renew a domain name

This guide will walk you through the process of renewing your domain name before a domain renewal...

Disable Domain Name Auto Renew Status

This guide will walk you through the steps of changing the auto renew status of a domain...