Disable web directory using Htaccess



When you are pointed to a directory on your web site through direct url which does not have an index file, Files in that directory can be listed on a web page. We can prevent the same with snippets of codes using htaccess. Preventing directory listings can be very useful. For example, you have a directory containing important ‘.zip’ archive files or to prevent viewing of your image directories. Alternatively it can also be useful to enable directory listings if they are not available on your server, for example if you wish to display directory listings of your important ‘.zip’ files. Here goes the Code in Htaccess…

Create a .htaccess file following the main instructions and guidance which includes the following text

IndexIgnore *

Above code which prevents the all directory listings with the folder(Server)
To prevent listing ‘.zip’ files, create a .htaccess file following the main instructions and guidance which includes the following text:

IndexIgnore *.zip

To prevent listing multiple file types, create a .htaccess file following the main instructions and guidance which includes the following text:

IndexIgnore *.zip *.jpg *.gif

Alternatively, if your server does not allow directory listings and you would like to enable them, create a .htaccess file following the main instructions and guidance
which includes the following text:

Options +Indexes

If you are not limited to htaccess you can do the same using httpd.conf.

Disable directory listing using httpd.conf :-

1) Open your httpd.conf, normally it

Reji Kumar (@rejikumar06) is a personal technology blogger and founder of Lab Inspiration, a widely-read tech and how-to blog since 2010. PHP Freelance, website design , website development, web hosting, SEO are also his strong areas of expertise. Email: info[at]rejionline.com

Tags:

 
 
 
Extension Factory Builder