Menu Close

How to Prevent Dir Listings or Show FancyIndex by htaccess file

To disable or prevent the directory access by browsers, you can add following code in your .htaccess file.
If user points the browsers to a directory which does not have index file then in this case 403 error will be:

Options -Indexes

403-directory-listing-error-htaccess

If you want all your files in your directory be shown to the browsers, you can add following code into your .htaccess file:


Options +Indexes

All your files including .zip, .gif, .jpg in this directory will be shown by all browsers.

Ignore files or Ignore files with specific extension

If you do not want any files and any sub-folders to be shown in the directory, you can add following code:


IndexIgnore *

If you just do not want your .zip, .gif, .jpg files to be shown, you can add following codes:


IndexIgnore *.zip *.jpg *.gif

Change Listing style

You may also want to add some details like file icons, file size, modification date and more. This can be done by adding fancy style to your htaccess file. You can add following codes:


IndexOptions +FancyIndexing

The directory browser will be shown like this:

fancy-directory-listing-htaccess

To remove the files details and fancy directory listing or to display normal directory listing, use -FancyIndex.

IndexOptions -FancyIndexing

Related Posts