Enabling/disabling directory listings using .htaccess

By default when accessing any directory which does not contain an index file on a cPanel server (ex: https://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 listings is by adding the following line to the .htaccess file in your public_html folder:

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.

On DirectAdmin servers, directories which do not contain an index file will display a "403 Forbidden" message by default. To enable the directory listing feature you will want to add the following line of code to the .htaccess file in your public_html folder:

Options +Indexes

  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

Introduction to .htaccess

What is .htaccess? The Apache Web server utilizes a per-directory access and configuration...

Creating custom error pages using .htaccess

One of the many things one can do to make their website a little more professional-looking is to...

Redirection using .htaccess

Most websites are constantly changing "works in progress" and as one updates, rearranges and...

Blocking users by IP address using .htaccess

Should you find that a few unruly visitors are causing you problems by posting unwanted messages...

Modifying existing .htaccess files

To modify/add directives to the .htaccess file in your public_html directory using "File...