What is the Hosts file and how to use it?
In this article we will explain what the Hosts file is and how to use it so you can run your web site(s) in Kentico CMS under different domain names (e.g. www.yourdomainname.com and yourdomainname.com).
What is hosts file and how to edit it
The hosts file is a computer file used in an operating system to map hostnames to IP addresses. The hosts file is a plain-text file and is traditionally named hosts.
For various reasons it may be necessary to update the hosts file on your computer to properly resolve a web site by its domain name. The most common reason for this is to allow people to view or publish web content immediately after purchasing a new domain name or transferring an existing domain name to another ISP (Internet Service Provider).
New and transferred domain names have a delay period that can be anywhere from a few hours to a few days. During this period of time the new or transferred domain information propagates around the internet, and is generally unavailable.
If you need to update your site immediately and cannot wait for the propagation of domain information around the internet, you can edit a file on your computer as a temporary work around.
this work around is only valid on the computer/server on which the change was made. It will not make the web site available to anyone on the internet.
Windows operating systems contain a file called ‘hosts’ that will force resolution of your domain name.
1. Open the hosts file
1. Go to the Start menu and choose Run. Type the following in the Run dialog box:
a. For Windows NT and Windows 2000:
b. Windows XP, Windows Vista or Windows 7
2. Click the OK button (This should open a window with several files in it.)
3. Find the file called ‘hosts’ and double–click it. If prompted, specify that you would like to choose a program to open the file with from a list of programs.
a. Choose ‘Notepad’ from the list of available programs.
2. Edit and save the hosts file
1. Start typing on a new line at the bottom of the file.
To do so, place your cursor at the very end of the last line and hit ‘Enter’ to start a new line.
2. Type these two lines of text like this example:
(use your server IP address and your site domain in–place of the defaults below)
a. 18.104.22.168 yourdomainname.com
b. 22.214.171.124 www.yourdomainname.com
3. Close the hosts file and save it when prompted.
3. Please note:
At this point you should be able to view and publish to your web site using your domain name on the computer where this change was made.
How to run multiple web sites in Kentico CMS using different domains (from hosts file)
How to run multiple web sites in Kentico CMS using domains from hosts file
In some cases you may want to run several web sites on your local computer or server on different domain names, so you do not have to switch the site off in Site Manager – for example you want to run your e-commerce site on http://myecommercesite
and at the same time a community site on http://mycommunitysite
In this case add following to the hosts file and save the change:
Now, please go to Site Manager -> Licenses tab and add license keys for the domain names you want to use for your sites (those added to the hosts file).
Next and last step is to add the domain name to the site settings in Site Manager -> Sites tab -> edit your site and add the domain name as the main “Site domain name” or on “Domain aliases” tab as a site domain alias.
After this, you can run the sites at the same time and access them under different domain names on your local computer or server.
See also: Multiple websites on a single domain (in subfolders)
Configuring multiple websites
Hosts file wiki
Editing your hosts file
What is the hosts file?
Kentico CMS, Windows OS