.htaccess disable everything including htaccess file and 404 mapping - how to do it?

How to do this in my .htaccess file for a specific directory in my root document ?:

  • Deny access to everything (including also .htaccess)
  • returns 404, not 403 error.
  • no files or subdirectories should be accessible or discovered by humans or bots
  • php local access allowed only

Sounds like that would be easy. This works, but throws 403 not 404:

deny from all 
+4
source share
3 answers

Have you tried something like this? This will result in 403 Forbidden error when someone tries to view something in the DIRECTORY. PHP scripts can access everything inside the directory. Obviously replace DIRECTORY with your preferred directory.

RewriteRule ^DIRECTORY - [F]

+1
source

I don’t like to send some html pages that say it is a 404 error, when in fact it is just a html page, which can also be located in Iamafake404error.html

Instead, you can try:

 Order Deny,Allow Deny from all Allow from 1.2.3.4 ErrorDocument 403 /throwaREAL404error.html ErrorDocument 404 /throwaREAL404error.html ErrorDocument 500 /throwaREAL404error.html ### never deliver .git folders, .gitIgnore RewriteRule ^(.*/)?\throwaREAL404error.html+ - [R=404,L] # 2nd line of defense (if no mod_rewrite) RedirectMatch 404 ^(.*/)?\throwaREAL404error+ 

https://serverfault.com/a/510951/194845

+1
source

Why not create a custom error page?

 deny from all ErrorDocument 403 /error/404.html 

The server always wants to reset error 403 if someone is not allowed to view the page and what you are trying to do. However, you can change the ErrorDocument for error 403 to show an HTML page that says error 404.

In my example, there is a folder in the root directory with the name error and an html file with the name 404.html .

0
source

All Articles