Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
SetEnv ENVIRONMENT PRODUCTION

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
add comment

2 Answers 2

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
add comment

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
1  
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
1  
.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
add comment

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.