Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Sep 10 '10 at 21:56

This question came from our site for professional and enthusiast programmers. There you will find examples and descriptions on solving your problem. – Tim Sep 10 '10 at 7:22

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

share|improve this answer

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
%-3 is the third item from the right so it's foo in

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)

So will be /var/www/site1/www/ will be /var/www/site2/www/
localhost will be /var/www/localhost/_/

then have fun with symlinks :-)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.