Enable/Disable directory listings using .htaccess

This section contains the codes and tips to improve the ranking of your site into the search engines. It will also contain info regarding the Mod Rewrite technique.

Enable/Disable directory listings using .htaccess

Postby MT Shahzad on March 20th, 2008, 10:18 am

By default when accessing any directory which does not contain an index file (ex: http://yourdomain.com/images/) a directory listing will be shown displaying a list of the files in that folder. 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 :

Code: Select all
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.

What’s especially nice about doing it this way is all sub-directories of that directory will also get their directory listings turned off. You could then turn on indexes for one of those sub-directories just by making a .htaccess file in that directory with:

Code: Select all
Options +indexes

If you want the directory contents to be listed, but only if they were HTML pages and not images. Adding the following line to the .htaccess file. IndexIgnore *.gif *.jpg This would return a list of all files not ending in .jpg or .gif, but would still list .txt, .html, etc .
MT Shahzad
Web/Software Developer
http://mts.sw3solutions.com
User avatar
MT Shahzad
Site Admin
 
Posts: 300
Joined: February 29th, 2008, 8:11 am
Location: Muridke, Pakistan

Return to SEO - Search Engine Optimization

Who is online

Users browsing this forum: No registered users and 0 guests

cron