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 on different folders.
This is for Apache-Windows configuration.
Steps
- Decide on the subdomain names...
For ex: sub.localhost, sub2.localhost, alt.localhost , images.localhost etc..
You can also name http://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) - Make the sites to point to 127.0.0.1, need to edit the HOSTS file on windows.
Add to HOSTS line
127.0.0.1 hostname
Ex:Code: Select all
127.0.0.1 sub.localhost 127.0.0.1 sub1.localhost 127.0.0.1 sub2.localhost 127.0.0.1 images.localhost 127.0.0.1 www.mysiteonmycomp.com
- Assign each of these different URL's to different folders.
Need to edit apache conf file. (httpd.conf file is at apache\conf\ directory)
Find Virtual Hosts in the file and then add as follows.
Code: Select all
NameVirtualHost *:80 #(This line was commented before) <VirtualHost *:80> ServerName subdomain name.localhost OR yoursite.com DocumentRoot Path to the server root, See examples. DirectoryIndex index.php index.html index.html index.htm index.shtml </VirtualHost>
Ex:Code: Select all
<VirtualHost *:80> ServerName sub.localhost DocumentRoot "C:/public_html/sub" DirectoryIndex index.php index.html index.html index.htm index.shtml </VirtualHost> <VirtualHost *:80> ServerName images.localhost DocumentRoot "C:/public_html/images" DirectoryIndex index.php index.html index.html index.htm index.shtml </VirtualHost> <VirtualHost *:80> ServerName site.com DocumentRoot "C:/public_html/site" DirectoryIndex index.php index.html index.html index.htm index.shtml </VirtualHost>
That's it.