1
<VirtualHost *:80>
    DocumentRoot /var/www
    <Directory />
    </Directory>
</VirtualHost>

Does the <Directory> tag refer to /var/www on the server, or /?

What would be the purpose of having a / configuration on a VirtualHost?

2

Apache applies configurations for directories to a request from smallest to largest. In essence the <Directory /> section specifies virtual host defaults; since every other possible directory will have that portion in its path.

If multiple (non-regular expression) sections match the directory (or one of its parents) containing a document, then the directives are applied in the order of shortest match first, interspersed with the directives from the .htaccess files. For example, with

<Directory />
  AllowOverride None
</Directory>

<Directory "/home">
  AllowOverride FileInfo 
</Directory>

for access to the document /home/web/dir/doc.html the steps are:

  • Apply directive AllowOverride None (disabling .htaccess files).
  • Apply directive AllowOverride FileInfo (for directory /home).
  • Apply any FileInfo directives in /home/.htaccess, /home/web/.htaccess and /home/web/dir/.htaccess in that order.

BTW, in the above example <Directory /home/web> would've worked the exact same way. The reason that isn't usually used though is because doing so will make moving your site to a new directory a little more difficult. It's easier to just use <Directory /> since that will work no matter where the site root is.

There is a full explanation on the Apache site: http://httpd.apache.org/docs/current/mod/core.html#directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.