How to Edit your Hosts File for Windows

Navigate to your hosts file

Your host file is typically located within c:\windows\system32\drivers\etc\hosts. If you don't see it there, other possibilities are as follows:

  • Windows 95/98/Me c:\windows\hosts
  • Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts
  • Windows XP Home/Vista/Windows 7 c:\windows\system32\drivers\etc\hosts
  • Windows 8 c:\windows\system32\drivers\etc\hosts
  • Windows 10 c:\windows\system32\drivers\etc\hosts

Backup your hosts file before you start editing

Best practices would suggest you to backup any file before you make any edits, whether that's a WordPress plugin, core or theme file. Here's the naming convention that I recommend: name_file_yyyymmdd. Here's an example id I were to do this backup today: host_file_20171109.

Follow these steps:

  1. Located the host file using the steps above.
  2. Right-click on the file and select Copy.
  3. Go to the Desktop or any location where you want to store the backup file.
  4. Right-click and select Paste.
  5. Right-click on the file and select Rename.
  6. Change the file name using the suggested naming convention above (name_file_yyyymmdd)
  7. Hit Enter on your keyboard or click somewhere on your Desktop away from the file to save the new name.

Opening your hosts file

Now that the backup is complete, navigate back to the location of the original host file. Since host files are not in a standard .txt file format, we will need to select the program we would like to open the file with. I suggest using Notepad since the program is installed with the Windows operating system and it's easy to use. Right-click on the host file and selecting Open With from the right-click menu. From the right-click menu, select Notepad.

Modifying your hosts file

Within your hosts file, you should see something like the following:

Windows Host File Screenshot

Below the last # symbol, enter the IP Address of the development or testing server. You should enter two lines, one for the www version and another for the non-www version. See the example below.

127.0.0.1 www.mydomain.com
127.0.0.1 mydomain.com

0/5 (0 Reviews)