0

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.

Jeff
  • 1,416
  • 3
  • 28
  • 50

1 Answers1

0

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.

adaptr
  • 16,576
  • 23
  • 34
  • 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