How To Hide Directory Viewing

There is probably a simple answer to this, but how do I keep visitors from being able to see the full file listing in any directory, i.e. the index of files in a directory?

In other words, anyone can find the URL to an image on my site such as then delete the image name and call up and see a listing of all images in this directory. This can be done with any directory on my site.

I know this can be prevented but don’t know how…



The simplest thing is to do is create a .htaccess file in your directory that you do not want viewable.

Create a file called .htaccess

Insert one line into the file:
Options -Indexes

Now drop that file in the directory you do not want viewable.

Save [color=#CC0000]$97[/color] on Dreamhost plans by using promo code: [color=#CC0000]SRVR97[/color]

Thanks! Works like a charm. I have, however, seen other sites where this action reroutes you back to the home page, whereas this .htaccess file generates a Forbidden error page. Is that also easy?



A kludge to do this would be to get rid of that .htaccess NoIndex option and put an “empty” index.html file with a META REFRESH tag in the head.


another tricky way is to place an empty index.html file in the directory

Save $97 with promo code: [color=#CC0000]97YES Sign Up NOW[/color]

Or just take out the .htaccess and create an index.php file which includes:

<?php header( 'Location:' ) ; ?>

Will automatically direct them back to your page.

Save [color=#CC0000]$97[/color] on Dreamhost plans by using promo code: [color=#CC0000]SRVR97[/color]