Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requests to .htaccess should return 404 instead of 403

This is sort of a follow-up to Is there a way to force apache to return 404 instead of 403? which suggested RedirectMatch to 404 to accomplish this.

It works perfectly fine for most of anything, however if I request:

 http://example.com/.htaccess

I get a 403 and not a 404 if I have (or not) this in my .htaccess file:

RedirectMatch 404 ^/\.htaccess$

Is there a way to override the default 403 - Forbidden behavior of apache from inside the .htaccess file itself?

like image 585
hakre Avatar asked Nov 13 '22 15:11

hakre


1 Answers

Just after I posted my question, I came to a solution towards the following:

  • Mimic the default server configuration's <Files> rules for .ht type of files.
  • Allow them.
  • Redirect them to 404.

Works like this:

<Files ~ "^\.ht">
  Order Deny,Allow
  Allow from all
  Satisfy All
  Redirect 404 /
</Files>
like image 113
hakre Avatar answered Dec 21 '22 22:12

hakre