Our site remains ad-free thanks to our affiliates. This post's featured affiliate is Fiverr. Fiverr connects businesses with freelancers offering digital services in 300+ categories.
The post is not sponsored by the above affiliate and the content here is not representative of their company.
If you are working on many sites on a localhost, you might want to assign “Fake Domains” to each of those sites. Or if you need to point to a site instead of the file path, this tutorial will help you.
First, you need to have Apache installed, this can be installed using software packages such as XAMPP.
Go to your Apache Configuration File, which is located under
This location will vary on where you installed XAMPP.
Now, in this file you need to create a VirtualHost for each “domain” you want, and create one for localhost.
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "C:/xampp/www" ServerName localhost </VirtualHost>
Since we have localhost setup, we can add all the extra domains we want, for example “domain.tld”.
<VirtualHost *:80> DocumentRoot "C:/xampp/www/domain.tld" ServerName domain.tld </VirtualHost>
You can repeat the code above with as many domains as you want, and the DocumentRoot can be any location you want, that you have permissions for.
There is one last step, which is to edit the
HOSTS file in Windows to
allow the “domain.tld” to point to localhost.
- Open up notepad as administrator, by finding Notepad under the Start Menu, right clicking and “Run as administrator”.
- Go to Open, and find the file
- Make sure “All Files” in the open dialog is selected, and not just “*.txt”.
- On the bottom of the
HOSTSfile, you want to add this line for each domain you want pointed to your server. If you are using real domain names, access to those domains will no longer be allowed, since it will now point to your local server.
We map domain.tld to 127.0.0.1 (which is localhost).
There you have it, now you can access your site by going to domain.tld instead of localhost/domain.tld, and you can do this for any domain you want.