How To Hide Directory Viewing


#1

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 http://www.crunchentertainment.com/crunch_images/CL_01b.jpg then delete the image name and call up http://www.crunchentertainment.com/crunch_images/ 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…

Thanks.

Jeff


#2

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]


#3

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?

Thanks.

Jeff


#4

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.

-Scott


#5

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]


#6

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

<?php header( 'Location: http://www.yoursite.com' ) ; ?>

Will automatically direct them back to your page.

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