Um... everyone so far has been proposing workarounds instead of just getting to the source of the problem. Making it so a 404.html page shows up is a non-standard behavior, for sure. What you want is for Apache to output a 403 Forbidden page, which is done automatically, if you change your settings as I describe below.
Apache only lists directories if:
1. mod_autoindex is loaded. If you want to completely turn off this behaviour, just comment out:
#LoadModule autoindex_module libexec/mod_autoindex.so
and
#AddModule mod_autoindex.c
or... if you want this setting to be available, but turned off by default, then see point 2.
2. The <Directory /path> container for the location in question has "Indexes" listed among the Options, as in:
<Directory "/usr/local/apache/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
The above lists a fairly "wide open" setting, where indexes are available for any directory without an "index.html" file. To disallow directory browsing, simply do
<Directory "/usr/local/apache/htdocs">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
(Note: you might want to take out MultiViews also, if you are really security-conscious, even though it doesn't directly deal with the same issue)
Now, we have configured the system by default to restrict directory viewing, but let's say we want a certain folder to allow browsing. Then we can add an .htaccess file in that directory which turns on the behavior, or we can just specify in httpd.conf:
<Directory "/home/rick/public_html/mysharedfiles">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
By the way, do you want your own special icons in the Apache directory indexing? Just go to the <IfModule mod_autoindex.c> section of httpd.conf, and you will see where the lists of icons are defined. Just point to your own icons, and you have a customized directory listing ;-).
-------------------------------------------
"Now, this might cause some discomfort..."
(