Drivel, and everything else..

06 Feb, 2009

How to prevent/enable directory listing with .htaccess

Posted by: Rob In: Uncategorized

If a directory on your website doesn’t have an index page, then by default it’ll present the user with a directory listing. This isn’t usually a good thing, especially if it’s an image directory. You can prevent this from happening by modifying your .htaccess file (or creating it if you don’t have one).

Open your .htaccess file in notepad (or create one) and put:

IndexIgnore *

The * is a wildcard that matches everything, so if you put this in your htaccess file in your images directory, nothing in that directory will be listed.

If you want the directory contents to be listed, but ignoring certain files, you can:

IndexIgnore *.gif *.jpg

This will ignore all .gif and .jpg files in the directory, but list everything else.

Alternatively, if you want to blanket block all directory listing from all directories on your website, simply put the following in a .htaccess file in the root of your website (usually public_html):

Options -Indexes

… and lastly, if your web server already blocks directory listing by default (some apache webservers have this configured by default), but you want to enable directory listing for a particular directory, stick this in the .htaccess in the directory:

Options +Indexes

No Responses to "How to prevent/enable directory listing with .htaccess"

Comment Form

Flickr PhotoStream

    The. An apple a day keeps the doctor a day. This is what they meant, right? Sunset New hobby P1000367 Our new flat

About

My name is Rob, and i'll be scribbling down interesting things, uninteresting things and general thoughts about anything I come across in everyday life. It may just turn into a 'Rant Archive' but hey, everybody needs an outlet. It's better than punching a wall, right?


What I'm Doing...