Home / Fix guides / Website security

How to disable directory listing in Apache

Directory listing shows visitors a public list of the files in a folder that has no home page file. On Apache, add Options -Indexes to your .htaccess file or site configuration, and the server will return a 403 Forbidden page instead.

Directory listing means that when someone opens a folder on your website that has no index.html or index.php file in it, the web server shows a plain list of everything inside that folder instead of a page. It is a server setting, not a hack, and it is easy to turn off.

What people see

Open an address such as https://example.com/uploads/ and, if listing is on, you get a bare page titled "Index of /uploads". Below it is a list of file names with dates and sizes, plus a "Parent Directory" link. Anyone can click through the folders, and so can search engines and automated scanners.

On Apache this comes from the mod_autoindex module together with the Indexes option. Some shared hosts and fresh installs have it switched on by default, so many owners never chose it.

Why it matters

  • Security: listings can expose files you never meant to publish, such as backup.zip, site.sql, config.php.old, logs, exports or test files. The listing does not break in by itself, but it hands an attacker a map of your site.
  • Search: search engines can index listing pages and the files in them, so strange file names may show up in results under your domain.
  • Trust and sales: a visitor who lands on a raw file list sees a site that looks unmaintained. Customers, partners and security questionnaires may also flag it.

One honest limit: turning listing off hides the list, but it does not protect a file whose exact address is known or guessed. Anything sensitive should be moved out of the public web folder or protected properly.

How to check if your site has it (free)

  1. Open a folder address in your browser, for example /images/, /uploads/, /wp-content/uploads/, /assets/ or /backup/. If you see "Index of", listing is on. A 403 Forbidden, a 404 or a normal page is fine.
  2. Or run this in a terminal: curl -s https://example.com/uploads/ | grep -i "index of". Any output means listing is on.
  3. Search Google for site:example.com intitle:"index of" (use your own domain). Any result is a listing that Google has already found.
  4. A security scanner will test many folders for you. The week 2 OpenVAS security scan from SiteMonday checks for this, and it only runs after you prove you own the site.

How to fix it on Apache

There are two usual ways. Use the first if you do not control the server, and the second if you do.

Option A: the `.htaccess` file. Open the .htaccess file in your website's root folder (the one that holds your home page). Create it if it does not exist. Add this line:

Options -Indexes

It applies to that folder and every folder below it. It only works if the server allows it through AllowOverride. If your site shows a 500 Internal Server Error after you add the line, remove it, because the server does not permit Options in .htaccess. Ask your host to allow it, or use Option B.

Option B: the server or virtual host configuration. Find the <Directory> block for your site and make sure it removes Indexes:

<Directory /var/www/example.com/public_html>
    Options -Indexes
</Directory>

If you already see a line like Options Indexes FollowSymLinks, delete the word Indexes from it. Then test the configuration and reload Apache:

sudo apachectl configtest
sudo systemctl reload apache2

On Red Hat style systems (RHEL, AlmaLinux, Rocky) the service is usually called httpd, so use sudo systemctl reload httpd. File locations vary by system: Debian and Ubuntu usually keep sites in /etc/apache2/sites-available/, Red Hat style systems in /etc/httpd/conf.d/.

Do not rely on IndexIgnore * alone. It hides the file names but still serves the listing page.

Other platforms and hosts

The setting has a different name depending on where your site runs:

  • cPanel: look for the Indexes or Index Manager tool (usually under the Advanced section, depending on your cPanel version), pick the folder and choose No Indexing. See the cPanel guide.
  • WordPress: WordPress does not control this, the web server does. On Apache, add the .htaccess line above to the site root. See the WordPress guide.
  • Nginx: the setting is autoindex off; in the relevant server or location block. See the Nginx guide.
  • IIS: open IIS Manager, select the site, open Directory Browsing and choose Disable.
  • Plesk and managed hosts: menu names depend on your version and plan. Usually you either edit .htaccess or add the directive in the hosting panel. If you cannot find it, ask your host's support to disable directory listing for your site.

How to confirm the fix worked

  1. Reload the folder address that showed the list earlier, using a hard refresh (Ctrl+F5 or Cmd+Shift+R) so you do not see a cached page.
  2. You should now see a 403 Forbidden message or a normal page, not "Index of".
  3. In a terminal, curl -I https://example.com/uploads/ should show 403 on the first line of the response.
  4. Check a few subfolders too. A more specific <Directory> block or a .htaccess file deeper in the site can switch listing back on with Options +Indexes.
  5. If Google had already indexed listing pages, they drop out over time. You can speed this up with the Removals tool in Google Search Console.

How to stop it coming back

  • Set the rule once in the main server config or the root .htaccess, and keep a copy of that file in your backups or version control.
  • Never leave backups, database dumps or exports inside the public web folder. Store them outside it.
  • Recheck after a hosting move, a server rebuild, a new site install or a change of host. Fresh setups often reset to the default.
  • As a second layer, place an empty index.html file in folders like uploads, so even a missed setting shows a blank page.
  • Scan again now and then. SiteMonday reports this kind of problem and ranks it in a fix list, but the change itself is for you or your developer to make.

Step by step for your platform

Questions

Does Options -Indexes hurt my website or SEO?

No. Visitors and search engines still reach every page and file that has a direct link. Only the automatic folder list disappears, and that is usually good for SEO.

Why do I get a 500 error after adding Options -Indexes to .htaccess?

Your server's `AllowOverride` setting does not permit the `Options` directive in `.htaccess`. Remove the line and ask your host to allow it, or put the setting in the main server configuration instead.

Is directory listing the same as a hacked site?

No. It is a server setting that exposes folder contents to anyone who asks. It does mean files may be visible that you did not intend to share, so it is worth fixing quickly.

Will turning off directory listing protect my private files?

Not fully. It stops people browsing the list, but anyone with the exact file address can still download the file. Move sensitive files out of the web folder or require a login.

Can I turn off directory listing for just one folder?

Yes. Put a `.htaccess` file with `Options -Indexes` inside that folder, or use a `<Directory>` block for it in the server configuration.

Do I need to restart Apache after editing .htaccess?

No, `.htaccess` changes take effect on the next request. Changes to the main server or virtual host configuration need a reload, after testing with `apachectl configtest`.

Related problems