I use root relative path for all the links in PHP files, like "url(/img/myimj.jpg)"

In Godaddy host server, that works fine.

But I want to run it in my local host. (Ubuntu 9, Apache 2, PHP 5)

For example, I have my site stored in var/www/siteone, another one stored in var/www/sitetwo,

and root directory is set to "var/www".

Now the problem is a href="/" is not linking to var/www/siteone, but var/www/.

Is there a way to define different document roots for different sites?

I am just beginner in web development, not sure if vitual host can do it.

Could someone explain it?

Thanks for your answers.

I need to add new vitualhost to this file /etc/apache2/sites-available/default

But I am still confusing, how to do it for localhost? The default IP and port is always

migrated from stackoverflow.com Sep 10 '10 at 21:56

This question came from our site for professional and enthusiast programmers.


Each <VirtualHost> section can have its own DocumentRoot directive.


I personnally use a lot of VirtualDocumentRoot :

With this directive, you can do for exemple :

VirtualDocumentRoot /var/www/%-2/%-3/

%-2 is the "2nd item from the right" so it's exemple in exemple.com
%-3 is the third item from the right so it's foo in foo.exemple.com

Then you just have to make folders to match your hostnames :
localhost/ will be :


Notice the _ where there is no value (i always make a symlink like _ -> www)

www.site1.com will be /var/www/site1/www/
www.site2.com will be /var/www/site2/www/
localhost will be /var/www/localhost/_/

then have fun with symlinks :-)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.