Webmasters Stack Exchange is a question and answer site for pro webmasters. 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

Our server is configured with multiple domains which reside in subfolders of the public_html folder. So domain1.com is located in /home/user/public_html/domain1.com and domain2.com is located in /home/user/public_html/domain2.com and so on.

I've placed a .htaccess file in /home/user/public_html so I can put settings in it that apply to all domains. I've added two things to this .htaccess file. One is a special environment variable which is getting recognized by PHP just fine. The other is a redirect for any folder called .svn to a file called non-existant. So my .htaccess file looks like this:

RewriteEngine on
RewriteRule /\.svn /non-existant

The problem is that the rewrite rule isn't working at all. The environment variable is, so I know this file is being processed by Apache, but the rewrite rule doesn't work. I've tried several other rewrite rules and none of them seem to be working.

Do rewrite rules only work if they are in the document_root?

share|improve this question

You're not matching the .svn folder correctly:

RewriteEngine on
RewriteRule  ^(.*/)*\.svn/ /non-existant

I would actually redirect as a 403 Forbidden:

RewriteRule  ^(.*/)*\.svn/ /non-existant [F,L]
share|improve this answer

Apache only looks for .htaccess files within the document root. It sounds like you have multiple document roots -- one for each domain. The only place that you could put a central rewrite rule for all of them would be in Apache's httpd.conf file.

share|improve this answer
Apache will look all the way up to / if AllowOverride is set that way. See httpd.apache.org/docs/trunk/howto/htaccess.html – Dan Aug 23 '13 at 15:30
It sounds like they were expecting a .htaccess file outside the document root to take effect. – Stephen Ostermiller Aug 23 '13 at 15:48
.htaccess files can exist above the document root. The fact the environemnt var was set proves it was being called. – Dan Aug 23 '13 at 15:55
Good point on the environment var. – Stephen Ostermiller Aug 23 '13 at 16:19

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.