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

In my httpd.conf I have:

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all

And in my .htaccess file I have:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

When I HTTP to I expect to be redirected to, but instead the RewriteRule never happens. The client is never redirected to www. The client is redirected properly in all other cases.

I don't have any ErrorDocument directives.

Just wondering why this happens and how to correct this behavior on 403's.

share|improve this question
up vote 0 down vote accepted

Since you have access to httpd.conf, there is no reason to use .htaccess.

What context is the FilesMatch in ? Is it inside a vhost ?

The following achieves the same result, but better:

<VirtualHost *:80>
  Redirect /

<VirtualHost *:80>
  DocumentRoot /var/www/something

There are no odd side-effects, either.

share|improve this answer
FilesMatch is in the global scope. I really prefer to use .htaccess if at all possible. If, however, you're telling me there's no way to achieve a redirect inside my .htaccess in the case of a 403, I may change my plans. – Jeff Oct 15 '12 at 17:25
I'm not saying there is no way, but I will tell you that the order of request processing is different between htaccess and config. – adaptr Oct 15 '12 at 17:26
Lesson learned: Scope is everything with Apache. This seems to be the best solution if you have access to your main httpd.conf file. Thanks. – Jeff Oct 15 '12 at 18:46

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.