When we’re developing a website, there comes a time in the process (after the initial designs have been approved and we’ve placed the website-in-progress onto an online development environment), when changing the hosts file on a PC becomes necessary in order for our client to view a working version of their new site.
If the domain name is brand new, then we generally place the site on the new URL with a password protected front end. Changing the hosts file is not necessary in this case.
However, if the website is replacing an older site and we want to present it to our client under the correct, final domain without making it publicly visible, then we have to tell our PC (and our client’s PC) to find the new version of the website when visiting the established URL.
For example, if we were re-designing the Tinstar Design website – www.tinstar.co.uk – and we wanted a colleague’s opinion on the work-in-progress, we would upload it to a new server under the URL www.tinstar.co.uk. Then we (and our colleague) would need to edit the ‘hosts’ file on our respective PCs. This file can be used to tell the PC to look at a specific IP address when a specific URL is entered into a browser.
So if you want to preview a website on a development server before changing DNS or nameserver settings, here’s how it’s done:
On a PC Running MS Windows
Open the following file using Notepad:
or via File Explorer:
Right-click on the file, select open with…, search through windows / Notepad.
Underneath all the entries (anything prefixed by a # is commented out), enter the following (replace the number with the IP address of your development server):
123.456.789.101 yourwebsite.com www.yourwebsite.com
Save and close the hosts file. Restart your browser and you should see the development website under the correct domain name. From Windows 7 and up, you’ll need to run Notepad as an administrator to be able to save the file.
On an Apple Mac
Open Terminal. Type in:
Enter your password when prompted. Then type:
$sudo nano /private/etc/hosts
This will open the hosts file – it looks much the same as the PC version. Change it in the same way as above. Control-O will save it. Control-X will close the file. Then type ‘exit‘ then <return> – after which you can quit Terminal.
Visit the website
After completing the above steps, when you type in the URL to any browser, you should see the website-in-development. If you don’t, quit the browser, restart it and try again. You might have to clear the cache and history in order to let the browser catch up.