Hide folders with .htaccess

If you really want to show a 404 error for subfolder(s) , try the following in /.htaccess :

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=404,L]

If an existent /folder or /subfolder is requested, the above rule will rewrite it to /404 .


What you want is probably

Options -Indexes

which will just give a 404 error if no DirectoryIndex file is found.


IndexIgnore *

The above would prevent all files from being listed. Here * acts as a wildcard. You could replace it with something more specific, if needed.


As mentioned by duskwuff, what you need is

Options - Indexes

This will cause a 403 forbidden error on that particular directory. Thus to provide a custom error page you will need

ErrorDocument   403 myErrorPage.html

Hope this helps