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

Enable or Disable Directory Listing with .htaccess in DirectAdmin

This guide shows you how to show or hide the list of files inside a folder on your website.

DirectAdmin2 min read12 steps4 screenshots

What is directory listing?

A directory is another word for a folder. Normally a folder on your site has a main page, often named index.html or index.php. If it does not, the web server may show a plain list of every file in the folder. That is directory listing.

This is risky. Visitors can see file names you did not mean to share. For most sites it is best to keep it off. For a download area, you may want it on.

What is .htaccess?

The .htaccess file is a small settings file used by the Apache web server. Rules in it apply to the folder it sits in and to every folder inside it.

Warning: a wrong line can break your site. Make a backup copy of the file first.

Disable directory listing

  1. Log in to DirectAdmin.
  2. Open File Manager.
  3. Go to the folder you want to protect. For the whole site, use public_html.
  4. Find .htaccess. If it does not exist, click Create New File and name it .htaccess.
  5. Click the file, then click Edit.
    Screenshot: Click the file, then click Edit .
  6. Add this line:
Options -Indexes

The minus sign turns off the file list. Visitors will see a 403 Forbidden error instead.

  1. Click Save.

Enable directory listing

  1. Open the .htaccess file in the folder where you want a list.
  2. Add or change the line to:
Options +Indexes

The plus sign turns the file list on for that folder.

  1. Click Save.

Test it

  1. Open the folder address in your browser, like yourdomain.com/downloads/.
  2. Check that you see either the file list or an error, as you wanted.
Tip: If you get a 500 error after saving, remove the line you added. Some servers do not allow the Options setting in .htaccess. Ask Hostvento through the ticket page.

Quick recap

  • Directory listing shows the files in a folder with no index page.
    Screenshot: Directory listing shows the files in a folder with no index page.
  • Options -Indexes turns it off.
    Screenshot: Options -Indexes turns it off.
  • Options +Indexes turns it on.
    Screenshot: Options +Indexes turns it on.
  • Edit .htaccess in File Manager and back it up first.