Change Host File


If you ever want to preview a website before going live with it by pointing to the A Record, you have the option of changing your host file. This allows you to command the computer to view a website that is not live. 

For example, you have  test.com hosted on IP Address 12.12.12.123 but you have the same website hosted on a different server. Well if you want to preview the site on the other server, you can use this method to tell your computer to view a website hosted on a specific server. This only works if the website already resides on the specified server ip address.

To do this follow the instructions below:

1.) Open Notepad++ as an administrator by right-clicking the app icon and clicking  "Run as Administrator"

2.) Open the following path c:\Windows\System32\Drivers\etc

3.) You should see a file called hosts.txt Open this file

4.) Add a new line to the bottom of the opened document with the following syntax:

[IP Address] 
12.12.12.123 example.com www.example.com

5.) Try going to the website now, it should be up now.

Notes:

If you cannot tell if you are viewing the right website, you can create a lwHostsCheck.php file in the public_html folder and paste the following into the file:

<html>
<head>
<title>Migration Test Page</title>
<style>
body {text-align:center;font-size:20px;line-height:25px;font-weight:bold;font-family:Arial,sans-serif;background-color:#2AC4F3;}
.t {font-size:50px;line-height:50px;padding:21px;color:#FFFFFF;}
.i {width:50%;margin-left:25%;text-align:left;}
</style>
</head>
<body>
<?php
echo "<div class='t'>This is the new server!</div>";

$baseurl=$_SERVER['SERVER_NAME'];

echo "You're accessing: " . $baseurl . "<br>";

echo "This server's Ip: " . $_SERVER['SERVER_ADDR'] . "<br>";

echo "This server's hostname: ";
if (function_exists('gethostname')) {
  echo gethostname() ;
} else {
  //for php < 5.3
  echo php_uname('n');
}
echo "<br><br>";

echo "This page is unique to the destination of your migration. If you are seeing it, you have correctly modified your hosts file, and are ready to test this domain on the target server.<br><br>";

//get baseurl to direct customer to testing info
echo "Test this domain here: <a href=http://" . $baseurl . ">" . $baseurl . "</a>";

?>
</body>
</html>

​


Once you do that try opening the link by going to example.com/lwHostsCheck.php You should be able to see the details about the server, which will let you know where the website is hosted.

If you still see the wrong website try

open Command Prompt type in command > ipconfig /flushdns and press enter. Then trying refreshing the page.

Also try clearing you browsers cache.


Did you find this article useful?