Intro Developing websites on localhost may sometimes need making of sub domains. Installing and running another server for this purpose is useless, consumes more resources etc. So here is the technique to make sub domains on localhost.
You can also use this to host more than one site on localhost. i.e, you can host multiple sites situated on different folders.
PS: This is for Apache configuration.
First decide on the subdomain names… for eg: sub.localhost, sub2.localhost, alt.localhost , images.localhost etc.. You can also name www.name.com. (Please note that if there is a site with that name on the net, you wont be able to access that site on the internet.)
Second making these sites to point to
127.0.0.1, for this you can edit the HOSTS file on windows. The HOSTS file found on Windows (and linux too) is like a local DNS (domain name server). When you type a url on the browsers address bar, the domain name is converted to the IP of the server by a DNS lookup by the browser. Now here is the catch … Windows first looks at the HOSTS file before doing any DNS lookup. So we can block certain sites by editing the HOSTS file.
HOSTS file is found typically here …
Windows XP : C:\WINDOWS\SYSTEM32\DRIVERS\ETC
Windows 2K : C:\WINNT\SYSTEM32\DRIVERS\ETC
Windows 98/ME : C:\WINDOWS
Linux : /etc/
The Lines followed by a # are comments and explains how to use the HOSTS file.127.0.0.1 is the IP address that is used to loopback to your computer itself.
Now add to HOSTS line 127.0.0.1 <hostname> Egs:
1 2 3 4 5 6
Next we have to assign each of these different URL’s to different folders.
This is done on the apache conf file. (httpd.conf file situated in apache\conf\ directory).
Note that if you are using XAMPP, the virtual hosts file is at
Scroll all the way down the httpd.conf file until you reach about Virtual Hosts. Add for each domain (or subdomain)
1 2 3 4 5 6 7
You can also any valid extra parameters also (like ServerAdmin, ServerAlias etc.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
NOTE : All the DocumentRoots must be under the
DocumentRoot (i.e; must be a sub-directory) specified in
For example, in XAMPP, the default DocumentRoot is
C:/xampp/htdocs. Therefore, the DocumentRoot of any virtual host cannot be given as :
C:/xampp/test. The folder must be under