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?
Enable mod_rewrite and AllowOverride in /secret. Then create .htaccess:
I've looked around the internet for an answer to a similar problem. While mod_rewrite is a possible solution, I find the best solution uses the "RedirectMatch" directive.
See StackOverflow: Problem redirecting 403 Forbidden to 404 Not Found
Create a custom 403 script that returns an 404 error instead.
For example, in PHP:
Now configure Apache to use this script for 403 results:
No messing with rewrites and it instantly works for the whole server.
My solution to stop displaying directory's content as list and display 404 error is simple. Create .htaccess file in root directory of your project and write which directories should be protected.
Directories structure
.htaccess
The second line of .htaccess disallow access to list items in app directory and all its subridectories.
The third line of .htaccess disallow access to list items in models directory and all its subridectories.
The fourth of .htaccess line sets our own 404 error (if you do not want to show apache default error).
Remember to clear cache on your browser when you work with htaccess.
Use .htaccess to mask errors. See this guide:
http://www.tarahost.net/pages/web-design/29371.php