How to use hosts file to preview your website on new server

For cPanel users the default preview URL tool can cause some issues for complex sites, images may not load which can make checking everything is fine difficult or impossible.

Thankfully there is another way you can check your site, although it does mean editing your hosts file.

Editing the hosts file on your PC to bypass the DNS lookup and access the site on your webhosts servers through your main domain rather than the preview URL.

This only affects your PC and visitors to your website will see the site as normal.

Windows:

You need to open it with Administrator permissions, to do this right-click on the NotePad icon, select “Run as Administrator”.

Now, in NotePad open the file:  c:\windows\system32\drivers\etc\hosts

On OSX and Linux you may need to use sudo to gain root privileges to edit the file.

Mac OSX /private/etc/hosts

Linux /etc/hosts.

Once your hosts file is open add the following line:

Code:
192.168.1.1 www.danrodgers.uk danrodgers.uk

Replace 192.168.1.1 with the IP address of your site, as displayed in your control panel and replace “danrodgers.uk” with your real domain name.

Once you have made the change, save the file.

Now when you browse to your website as normal. You will see it served from the new server and will be able to test the full functionality of your website before editing the DNS

To view the site on your existing host, just remove the line from your hosts file.

Note: If this doesn’t work you might need to reboot your PC for the change to take effect.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.