Hosting : Test a website before changing nameservers

Checking, testing and previewing a website on a new server before switching DNS settings used to be relatively easy. Historically you would test your website via Apache’s userdir module. If your new hosting account username was, say, client1 then the temporary URL to the root of your website might be something like:

http://hostingcompany.com/~client1/

Using this method to test a website before DNS changes with modern Content Management Systems (CMS) like WordPress, Joomla, Drupla, Magento etc., simply won’t work. This is because of the way these systems rely on URL rewriting to produce a Search Engine Friendly URL structure. There’s simply no way to view the page http://mywebsite.com/products/hairdryer unless the domain mywebsite.com is pointing at the server hosting your website content.

It’s a common problem for website owners and developers alike. Whether you are moving a website from a development machine in the office (perhaps running XAMP or MAMP), or from another hosting provider, once it is on the new server you should test it before putting it into production (i.e. pointing the live domain at it).

There’s nothing worse, after switching the nameservers for your domain, than to find that your newly transferred website is dead on arrival. I’ve seen so many support tickets (in my day job) from website owners in this kind of peril. The only option at this stage is to spend a little time trying to find the fault, but more often panic sets in and you decide to change the nameservers back again. That just means another delay of an hour or two while the DNS information reverts to its original settings. Huge disruption! If this sounds at all familiar, then there’s a far safer way of doing things.

Cheating your computer’s internal DNS resolver

The trick is in making your computer think that the production domain really does point at the new server, while the rest of the world carries on fetching content from the old server.

Whenever your computer tries to resolve the IP address of a website (lets assume we’re looking for www.mycustomer.com), it follows these steps:

  1. do I have an entry for www.mycustomer.com in my local hosts file?
  2. do I have an entry for www.mycustomer.com in my local DNS cache that hasn’t expired?
  3. ask my ISP’s DNS servers to get the IP address for me.

If the process succeeds at stage 1 or 2, then it stops looking any further. This saves a lot of time, and makes life easier for the global DNS system. The trick is to intercept the process at stage 1, your local hosts file.

Altering the hosts file on Windows XP,Vista,7,8

You will need to open Notepad (or whichever text editor you prefer) as an administrator, so don’t forget to right-click Notepad and select Run as Administrator.

On a Windows PC, browse to the following location and open the hosts file.

C:\Windows\system32\drivers\etc

Altering the hosts file on Mac OSX or Linux

The hosts file can be edited by entering the following terminal command (you can find basic instructions for the pico editor here):

sudo pico /etc/hosts

Making the changes (all operating systems)

When editing the file do NOT adjust the settings that are already there. Simply add extra lines to the end of the file in the following format:

Replace 1.2.3.4 with the IP address of your new server, and www.mywebsite.com with the Fully Qualified Domain Name (FWDN – this is just a fancy way to saying the full host address) of your website.

Linux will recognise the changes straight away, but Windows may need to be restarted. You can test it out by going to a DOS Window or Terminal session in Linux and typing

which should give you the IP address of your new hosting server.

Doing it the easy way

Of course, there are a couple of application to help you do this without getting your hands dirty.

  • For windows users I can recommend HostsMan from abelhadigital.com
  • For Mac OSX users there is Gas Mask, which is available from Siim Raud

 

 

, ,

2 Responses to Hosting : Test a website before changing nameservers

  1. Rob the Robot March 31, 2015 at 10:34 #

    You can test your website using temporary URL from https://hosts.cx . It’s much simpler than messing around with hosts file and doesn’t require any app installation.

    • steve April 1, 2015 at 09:17 #

      Interesting service – of course, you really want to be sure that credential leakage doesn’t endanger your hosting account as all request data will be parsed by hosts.cx

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.