Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

This syntax seems to prevent Apache from serving any pages from /var/www or subdirectories.

 <Directory "/var/www">
     Allow from None
     Order allow,deny

I wantthis behavior as a general rule, with some exceptions. For example I want users to be able to access


but not:

 ... and many more
share|improve this question
What is it you're wondering? You already know that the Directory directive gives you a way to control your directories, what is it that's not working the way you want? – Jenny D Jan 9 '13 at 15:30

If you allow from none or deny from all then no one is allowed access to the directory content.

if you want finer control than all or nothing you should look at the access controls in the apache docs which is basically

[ allow | deny ] from address

address can be a domain an ip or a hostname.

share|improve this answer

You could work with DirectoryMatch to set a deny rule on most directories except some of them.

But I think your real problem is that you have a lot of folders inside your web directory root (/var/www) and you do not want anyone to access theses directories. So why are they here?

A cleaner path organisation would be:

  • /path/to/project : the project root
  • /path/to/project/www : the project apache document root (DocumentRoot))
  • /path/to/project/www/[js|css] : some valid web assets
  • /path/to/project/lib : libraries of the apllication, the code
  • /path/to/project/lib/[app|xml|foo|bar] : libraries of the aplication, the code
  • /path/to/project/[etc|doc|var|tmp] : other things

Apache cannot access anything before the DocumentRoot except if you set some aliases, but you do not need aliases. all the things that do not require derect access via an url should not be under the DocumentRoot. Most CMS ignores this basic rule simply because they want to be easily deployed on very restrictive hosts policies (where you only have access tco the document root via ftp).

This could be done with any language, jsp' asp' php. You only need a bootstraper file (namely index.php, index.jsp, index.asp) in the web directory root, any other resource is loaded into the application via include directives and library path settings.

You will avoid a lot of information disclosure problems with that (except for all the stuff you could find attached to js libraries packages, be sure to suspend php execution on js assets paths).

share|improve this answer

Your Answer


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.