Fixed Knowledge Base

Get all the help you need here.

Preview a Wordpress Website

Posted 04th October, 2018

Because Wordpress uses a main domain, it requires that domain to be pointing to the right location/server in order to function correctly. However, there may be reasons that a website is displayed, when the domain still points elsewhere. For example:

  • On a newly built website that is not yet live.
  • On a development version of a website
  • When migrating a website from one provider to another.

Previewing a WordPress website can therefore be done by temporarily changing the URL on a website, or by fooling your computer into thinking that the domain is already pointing to the new server.

Content

  • Preview URLs
  • Hosts file entries

Preview URLs

Preview, or 'Temporary' URLs are given by a web hosting provider as a way of viewing the website without the main domain. For example, servername.provider.com/~username (cPanel) or domainname.provider.com. Alternatively, a second domain or subdomain could be pointed to the files as a domain alias.

Wordpress, however, will still request files and attempt to load content from the configured main domain as WordPress sees it.

For a preview url to therefore work correctly, the main domain should be changed. Because the domain does not yet point to the server, this may need to be changed in the database.

Once the actual domain points to the WordPress site, the main domain can then be reverted.

'Hosts' File Entries

When a computer looks up a website location it uses a DNS query. This gives it the IP Address of your web server. If a domain does not yet point to a server, then the wrong IP address (or no IP address) will be returned.

A hosts file presets the IP address on your computer, skipping the lookup and forcing your computer to see the domain on a specific location.

The hosts file has the following structure, with new entries added per line.

127.0.0.1 site.com www.site.com

First is the IP address. Second are the websites you want to force, separated by a space. Both the domain, and the www. portion of the domain are added above.

To revert back to DNS lookups, the line can be removed.

File locations

The hosts file is located differently on every operating system. Once updated the browser may need to be restarted, or the cache cleared. Viewing the site in incognito mode will force a cache refresh.

Windows

The hosts file requires administrator privileges to edit. This can be done by:

  1. Locate your Notepad instance
  2. Right click
  3. Click Run as Administrator
  4. Locate the file. Choose All files under the show option.
  5. The file is located at C:\windows\system32\drivers\etc\hosts

Mac OS/Linux:

The file is located in /etc/hosts. The easiest way to edit is with Terminal.

  1. Click the magnifying glass icon
  2. Type terminal and press enter
  3. Type sudo nano /etc/hosts and enter the administrator password when prompted.
  4. Press down to go to the end of the file, type in the new line and press Ctrl+x.
  5. Confirm the save.

Browser based alternative

Online hosts file or browser based extensions exist. These work on a browser level to allow overriding of the computer hosts file.