using virtual host in apache like virtual directory in windows

Apache Add comments

by default we have our files stored in a user defined path like d:\www\xampp\htdocs\site1
when we access we give as localhost/site1

using virtual host option you can use like the following
consider you have your site in d:\www\xampp\htdocs\site2
you can access your site as “http://site2″ or “” or “http://site2.local” … by updating the httpd.conf file
which will be present in the apache/conf folder of your installation.

edit your httpd.conf file and go to the bottom of it. and you can add like the following.
i assume that your default document root is d:\www\xampp\htdocs

   DocumentRoot "d:\www\xampp\htdocs\site1"
   ServerName site1

before using this you have to do two steps

one is restarting apache and the other is as follows

since we are going to give http://site1 windows will connect to the internet to fetch the site but we have to inform windows
not to connect to the www and instead connect to the local site1. for this you have to add the site1 in a windows file which
is stored in the following folder


the file name is “hosts” without extension

you have to add the following line in the file “hosts”       site1 or [if you want to access that way] or any of your wish

consider that you are having your site outside the default path of apache say d:\mysite
then you have to follow the steps below to include that

<Directory "D:\mysite">
  Order Deny,Allow
  Allow from all
and this besides the similar code
   DocumentRoot "d:\mysite"
   ServerName mysite

include the above better before NameVirtualHost

so you have two sites now and you can run your sites like the following
type in the address bar after restarting apache as “site1″ which will automatically be called as “http://site1″ and mysite whic will be like “http://mysite”

try it and enjoy…

Leave a Reply

Entries RSS