Monday, April 28, 2008

Disable Directory Listings in WordPress

By default when accessing any directory which does not contain an index file, a directory listing will be shown displaying a list of the files in that folder. Web servers can be configured to automatically display the listings of the contents of a web site's file directory if no index file (i.e. index.html or index.php) is present. This can expose files and information to visitors.

Simply adding a blank/ 0 byte text file named "index.html" will prevent this directory list from being displayed, however another way to disable directory listing is by adding the following line to the .htaccess file in your public_html folder of your web hosting account :

Options -Indexes

That’s it, with this line in place, folders which do not contain index files will no longer show the default directory list.