If you need to check, test or access a new website that is only accessible on a temporary URL, you may need to edit the hosts file to properly test the website.
This method of access can also be used to make changes to a staging website prior to the website going live or to simply verify the outcome of a migration.
The location of the hosts file and how to edit this depends on the operating system you are using.
Further down this page, there are guides for Windows, Mac, and Linux.
How the Hosts file works :
This basically works by tricking your computer into thinking that the DNS records have been updated on your Computer only. This allows you to access the website normally but loads from a different server. The hosts file itself needs to be updated with a specific syntax. This will be in the format of ‘IP domain(s)’, for example.
Windows
Locate ‘notepad’ in the start menu
- Right click on notepad and select ‘Run as Administrator’
- Click ‘File’ and then ‘Open’
- Navigate to the following location: ‘C:\Windows\System32\drivers\etc’
- First navigate to your C: drive
- Then navigate to the Windows folder
- Then find the System32 folder
- Then select drivers
- Then locate the etc folder
- Change ‘Text Documents (*.txt)’ to ‘All Files’
- Select ‘hosts’ and click ‘Open’
- Type in the details as required
- Ensure that you use the details provided in the migration email for this section.
When done save the file by clicking on ‘File’ and then ‘Save’
Mac
- Open Finder
- Select ‘Applications’, and then ‘Utilities’
Open ‘terminal’
- Type in ‘sudo nano /private/etc/hosts'(If this file is blank use ‘sudo nano /etc/hosts’)
Type in your computer’s password and press ‘Enter’. The screen will remain blank while doing this. Use the ‘down arrow’ key to navigate to the end of the file
- Type in the details as required
- Hold down the ‘Control’ key and press ‘O’ to save, then press ‘Enter’
- Hold down the ‘Control’ key and press ‘X’ to exit nano
- You can now exit terminal
- Open a terminal window
- Type in ‘sudo vi /etc/hosts’
- Type in your computer’s password and press ‘Enter’. The screen will remain blank while doing this
- Use either the down arrow or ‘j’ to navigate to the bottom of the file
- Press ‘i’ to enter insert mode
- Type in the details as required
- When done press ‘Esc’ to exit insert mode
- To close the file press either ‘Z’ twice or type the following ‘:wq’
- You can now exit terminal