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

Currently in apache2.conf I have AllowOverride all set for /var/www which simply allows htaccess for all the sites on the server (which is Ubuntu, 9.04).

However, I'd rather only allow overrides in each site root directory and nothing else. In other words, /var/www/site1, /var/www/site2, etc. can have a htaccess, but all other directories including /var/www and /var/www/site1/content cannot.

Is there a way to do this without having to write a rule for every site on the server?

EDIT: Maybe my question wasn't clear enough. But I have just tried a couple of things that didn't work as expected. I set AllowOverride none for the root directory then all for specific directories like this:

<Directory ~ "^/var/www/site1$">
  AllowOverride all

However, when loading a URL like the page cannot not be found (shows the browser error page, not my 404 page). Note section/page is not a real filesystem URL, it's a rewrite.

It was my understanding that:

  1. In the previous configuration, Apache would look for a htaccess in /var/www/site1/section (which doesn't exist), then try /var/www/site1, and then any parent directories.
  2. With the directives above, Apache should now just look at /var/www/site1 and no other directories. But that doesn't seem to be working...
share|improve this question

You can specify an arbitrary amount of Directory tags and configure them independently.

You can do this by VirtualHost too.


<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from all
share|improve this answer
That doesn't solve my problem though. I updated the question with more details. – DisgruntledGoat Mar 1 '11 at 11:41

You can set that by Virtual Hosts, if you are using Virtual Hosts.



share|improve this answer

I know this is pretty old but if anyone else comes across this, you can use the standard "*" wildcard character in paths, which matches any character except a slash, so the following would restrict htaccess to only your site root directories and no subdirectories:

<Directory />
    AllowOverride None
<Directory /var/www/site*>
    AllowOverride All
<Directory /var/www/site*/*>
    AllowOverride None
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.