Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Turn directory listing on or off with .htaccess

This guide shows how to control whether visitors can see a list of files in a folder of your website.

Files and FTP2 min read9 steps4 screenshots

What is directory listing?

Every web folder normally has a home page file, such as index.html. If a folder has no such file, the server may show a plain list of everything inside. This list is called directory listing. It is like leaving your desk drawer open for anyone to look through.

For most sites, it is best to turn it off. You may turn it on for a folder where you share downloads.

.htaccess is a small settings file used by Apache servers. Apache is the program that serves web pages.

Warning: a typing mistake in .htaccess can cause a "500 Internal Server Error". Make a backup copy of the file before you edit it.

Steps

  1. Log in to cPanel.
  2. Open File Manager.
  3. Click Settings at the top right. Tick Show Hidden Files (dotfiles). Click Save.
  4. Open the folder you want to control. Use public_html to cover the whole site.
  5. Look for .htaccess. If it is missing, click + File and create one with that name.
  6. Right-click the file and choose Copy to save a backup.
  7. Right-click .htaccess and choose Edit.

To disable directory listing

Add this line at the end of the file:

Options -Indexes

This stops the server from showing file lists. Visitors see "403 Forbidden" instead.

To enable directory listing

Add this line instead:

Options +Indexes

This lets the server show the list of files when no index file exists.

  1. Click Save Changes.
    Screenshot: Click Save Changes .
    Screenshot: Click Save Changes .
    Screenshot: Click Save Changes .
  2. Visit a folder address in your browser to test it.
Tip: The setting also applies to folders below the one holding the file. You can place another .htaccess in a subfolder to give it a different rule.

If you see a server error, remove the line you added or restore your backup. Open a support ticket if you need help.

Quick recap

  • Directory listing shows folder contents to visitors.
    Screenshot: Directory listing shows folder contents to visitors.
  • Options -Indexes turns it off.
  • Options +Indexes turns it on.
  • Back up .htaccess before you edit it.