The first thing to do is to locate the host
file, which is typically under /windows/system32/drivers/etc
. Usually this file contains the following line by default:
127.0.0.1 localhost
Then you can add the name of your local host, which must correspond to a physical directory on your PC:
127.0.0.1 localhost 127.0.0.2 yoursite
It doesn't matter whether you use "yoursite" or "yoursite.com" or even "www.yoursite.com": the important thing is that this name must correspond to a real directory. Done this, you can create a directory structure inside this folder, for example yoursite/htdocs
and add a VirtualHost
directive in Apache's httpd.conf
file by also setting the DocumentRoot
directive to a directory of your choice (in this case you can choose
htdocs
).
Note how the IP trick works: the last number on the right has been incremented by 1 (127.0.0.2), so you can add many other hosts to the host
file. Always remember to edit the configuration file of Apache or, even better, use a custom .htaccess
file.