Since I usually flip at least a few websites each month, I’m continuously acquiring domain names, setting up and removing hosting accounts. I prefer to design each website online rather than on my local computer, but I don’t want visitors or search engine spiders to find the site until it’s completely finished. How do I get around that?
Or, let’s say my website is setup with hosting company A and has been online for some time already, but I decide to switch to hosting company B instead. How do I transfer my website over to the new hosting company and ensure it’s functioning correctly without any downtime?
The solution to these questions is easier than you think. It all has to do with a little file called “hosts” that resides on your computer.
The Hosts File
The hosts file gives instructions to your computer to use a specific IP address when accessing a particular domain name. This goes for any type of access- the frontend website, cPanel, FTP, etc.
Your hosts file resides at:
Since your hosts file has no actual file extension, you will be prompted to select a program you would like to use when attempting to open the file. Any plain text editor would do such as Notepad, Notepad++ or Notepad2.
Once opened, you may or may not already have entries in the file. Spyware protection software such as Spybot Search & Destroy sometimes add entries to your hosts file to keep files from certain websites from installing on your computer.
Using Your Hosts File
Adding entries to your hosts file is very simple. All you have to do is enter the IP address you would like to specify followed by a space, then the domain name to associate to the IP address.
For example, let’s say you just purchased the domain name “example.com”, but you want to completely develop and test the website before anyone else would be able to see it. In order to do so, all you have to do is register the domain name without using the nameservers set by your hosting company. This way, the domain name would not resolve with the hosting company where you will be developing the website.
Then, you create a hosting account for your domain, example.com. You would then open your hosts file and create a new entry like so:
This would ensure any attempt to access example.com or www.example.com from your computer would resolve at the IP address 184.108.40.2060, which would be the IP address given to you from your hosting company. Again, this is only from your computer.
You could then develop and test your website online through your hosting account. Once it’s totally finished and ready to be released, you could then set the nameservers for the domain name given to you from your hosting company, which would now direct all traffic from your domain name to your hosting account for everyone to see. Now, from day 1 your site goes online to the public, it’s totally complete and functional. It’s not only a great feature from a visitor’s point of view, but also a great feature to keep your unfinished website being indexed by the search engines, then having those unfinished pages listed in search engines for weeks, months or even years later.
Switching Hosts With No Downtime
The same principle applies when it comes to switching hosting accounts. Let’s say your website, example.com, is hosted with company A, and the details are as follows:
Host: Company A
IP Address: 123.45.678.90
Nameservers: ns1.companya.com, ns2.companya.com
Now, you decide to switch web hosts to company B, and the details are as follows:
Host: Company B
IP Address: 987.65.432.10
Nameservers: ns1.companyb.com, ns2.companyb.com
What you would do is download all of the website files from company A. Then open up your hosts file and enter the following:
This would direct all access to example.com and www.example.com on your computer to hosting company B, while everyone else would still be directed to company A.
You can then upload your website files to company B, visit the site and test it throughly. Once you are sure everything is working fine, you can then change the nameservers for your domain example.com to:
After allowing 48-72 hours for the domain name propogation, all visitors to your website will now be redirected to hosting company B- with no downtime!
I like to wait at least a week or two to ensure everything is working fine, then I can delete the hosting account with company A since all the traffic to the website is now directed to my new hosting company.
Just a point to keep in mind when it comes to using your hosts file is to not forget to remove the entry you create once everything is setup. Otherwise, if the IP address used by your hosting company for your domain ever changes, or if you ever change hosting companies in the future, all attempts to visit the site from your computer will always be directed to the IP address you entered in your hosts file.
I find my hosts file extremely valuable as a website designer, and if you were unfamiliar with your hosts file until now, give some of these tips a try if given the opportunity. You will find that it makes for a much smoother transition for any changes with your domain name.