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 Xperience by Kentico under different domain names (e.g. www.yourdomainname.com and yourdomainname.com).
What is a “hosts” file and how do I 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, 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 this file on your computer as a temporary work around.
Please note: 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.
- Open the hosts file
- 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/10
- Click the OK button (This should open a window with several files in it.)
- 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.
- Edit and save the hosts file
- 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.
- 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. 220.127.116.11 yourdomainname.com
b. 18.104.22.168 www.yourdomainname.com
- Close the hosts file and save it when prompted. You will likely need Administrator privileges on your computer to save this file.
- 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 Xperience using different domains (from hosts file)
In some cases you may want to run several web sites on your local computer or a server on different domain names, and want to avoid having to switch the site off in the administrator interface for your site – for example, if 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 the following to the hosts file and save the changes:
Now, to setup the domains in the Xperience administrator interface, go to the License keys application and add license keys for the domain names you want to use for your sites (those domains that were added to the hosts file). The final step is to add the domain name to the site settings in the Sites application in Xperience. In the administrator interface, navigate to the Sites application and click on the pencil icon (✎) next to your site to edit it. Then, add the domain name as the main “Site domain name” or as a domain alias on the “Domain aliases” tab.
After this, you can run the sites at the same time and access them under different domain names on your local computer or server.
Running multiple sites on a single domain (in Subfolders) - Portal Engine only
Setting up multiple websites - Portal Engine only
Hosts file wiki