Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess deny all, including the htaccess file and display 404 - how do I do it?

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

  1. deny all access to anything (including the .htaccess too)
  2. return a 404, not a 403 error
  3. no files or subdirectories should be accessible or detected by humans or bots
  4. only php access by the local host would be allowed

Seems like it would be simple. This works but throws a 403 not a 404:

deny from all
like image 961
Inator Avatar asked Jun 14 '12 03:06

Inator


People also ask

What does Deny from all do in htaccess?

You just need to add a few commands to . htaccess to make it happen. For example, deny from all is a command that will allow you to apply access restrictions to your site.


1 Answers

Why not create a custom error page?

deny from all
ErrorDocument 403 /error/404.html

The server will always want to throw a 403 error if someone is not authorized to view the page and that's what you're trying to do. However, you can change the ErrorDocument for error 403 to show an HTML page that says it's a 404 error.

My example has a folder in the root directory named error and an html file in it named 404.html.

like image 125
Kenny Johnson Avatar answered Oct 08 '22 21:10

Kenny Johnson