Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In my httpd.conf I have:

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

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 example.com/.ht I expect to be redirected to www.example.com/.ht, 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

1 Answer 1

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>
  ServerName example.com
  Redirect / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www/something
</VirtualHost>

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

 
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.