Security – Disable directory listings with 404 instead of 403

apache-2.2directoryindexSecurity

I've disabled directory listings like so…

Options -Indexes

When I try and access a directory like this:-

www.example.com/secret/

I get a 403 Forbidden response.

However, I want a 404 Not Found response, so hackers can't guess my directory structure so easily. How would I do that?

Best Answer

Enable mod_rewrite and AllowOverride in /secret. Then create .htaccess:

RewriteEngine On
RewriteBase   /secret
RewriteRule   ^$ - [R=404,L]