5

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?

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • 3
    This has to be done on the main Apache configuration file or in your vhost, where access to .ht* files are returned with HTTP 403. You can simply change it there without having to do rewrite. – mauris Oct 30 '11 at 15:27
  • 1
    @thephpdeveloper: add that as an answer instead of a comment :) – Konerak Oct 30 '11 at 15:28
  • Thanks guys for confirming this. I only saw this one particular line once on the `httpd.conf` file relating to the `.ht*` files handling, so daren't confirm this. – mauris Oct 30 '11 at 15:29
  • @thephpdeveloper: No it has [*not*](http://stackoverflow.com/questions/7945795/requests-to-htaccess-should-return-404-instead-of-403/7945851#7945851) to be done in the main apache config file or vhost configuration. – hakre Oct 30 '11 at 15:34
  • And for the close-voters: I need this for the URL layout of my application configuration, I don't want to re-configure the whole server which I can not anyway as it's shared hosting (a fine one with git if that matters). So I would merely think of it as any other mod_rewrite configuration question here on SO which are fine. – hakre Oct 30 '11 at 15:36

1 Answers1

1

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>
hakre
  • 193,403
  • 52
  • 435
  • 836