Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.
<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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 explaination on the Apache site: http://httpd.apache.org/docs/current/mod/core.html#directory

share|improve this answer

Your Answer

 
discard

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

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