By default local ip address is 127.0.0.1 or 10.1.1.1 or something like that. So when we’re using apache on our local machine and when we try to access our default server we simply type http://127.0.0.1 as our local address.

But sometimes we want to use different addresses. For example we want to use mod_rewrite to manage some url addresses but it’s not easy when we’re working lots of sites in our local server where they’re in more directories like these :

127.0.0.1/mysite1
127.0.0.1/mysite2
127.0.0.1/mysite3

And of course there’re another reaosons for that. For example you want to link your pages or styles or images dedicated to root like /image1.jpg but it won’t work on sub directories in our web server.

Reasons can be extensible.

Our solution will be simple…

Open your httpd.conf file in your apache configuration directory. And add a line to the end of configuration script like this :

<VirtualHost 127.0.0.2>
DocumentRoot "E:/mysite1"
</VirtualHost>

Now when you enter url like http://127.0.0.2 it will manage E:/mysite1 directory as the root directory of the server.

You can extend these definitions according to your needs like this :

<VirtualHost 127.0.0.3>
DocumentRoot "E:/mysite3"
</VirtualHost>

<VirtualHost 127.0.0.4>
DocumentRoot "E:/mysite4"
</VirtualHost>

Every definition in our code will create a Virtual Host and tie it’s root directory to out DocumentRoot definition.

Tags: , , ,
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>