How to Disable Directory Listing in WordPress with .htaccess

How to Disable Directory Listing in WordPress with .htaccess

A media directory without an index file may reveal a generated list of filenames even though normal WordPress pages appear secure. Disabling that listing prevents casual browsing, but it does not make publicly accessible files private.

Confirm that Apache is generating the index, apply the narrow supported directive and test direct files as well as the directory URL.

Table of contents

  1. What it means
  2. A realistic WordPress example
  3. Why it matters and when to use it
  4. A straightforward route for beginners
  5. The advanced route
  6. Risks, common mistakes, backup, and rollback
  7. How AIOWS helps: AIOWS Htaccess Editor
  8. Related AIOWS articles
  9. Conclusion and recommended route
  10. Official sources

What it means

Directory listing is a web-server feature that builds an index when a requested directory has no recognized index document. On Apache, Options -Indexescommonly disables that behavior when the host allows the directive in .htaccess.

The setting changes the directory response, not file permissions. Anyone who knows the URL of a public upload may still request it.

A realistic WordPress example

A forgotten archive in an uploads subdirectory appears in an automatically generated filename list. Adding a placeholder index page would hide only the current view and could be bypassed elsewhere.

The administrator disables indexes at the appropriate directory scope, verifies that the directory no longer lists files and confirms that known images continue to load.

Why it matters and when to use it

Removing indexes reduces unintended discovery of backups, logs and predictable filenames. It is a useful baseline on directories that are meant to serve files but not enumerate them.

Sensitive material should not be stored under the public web root at all. Directory listing is not an access-control system.

A straightforward route for beginners

  1. Request the directory URL in a signed-out browser and record the response.
  2. Confirm the listing comes from Apache and locate the active .htaccessscope.
  3. Back up the complete file.
  4. Add the supported directory-index disabling directive outside WordPress markers.
  5. Retest the directory, a known file and an ordinary WordPress page.
  6. Move any private archives or logs out of public storage even if the listing is gone.

The advanced route

Review inherited Optionssettings and the host AllowOverride Optionspolicy. Some environments reject the directive with a 500 response instead of ignoring it.

Test subdirectories with and without index documents, CDN-cached responses and direct origin access. A WAF or edge-generated page can otherwise obscure what Apache actually returns.

Risks, common mistakes, backup, and rollback

An unsupported Optionsdirective can take the site offline. Applying it at the wrong level may also change directory behavior for another application.

Keep the original file and an external recovery path. Restore immediately on a server error, then use the hosting control designed for directory indexes.

How AIOWS helps:

AIOWS Htaccess Editor

AIOWS Htaccess Editor can maintain the supported Apache directive in the active file while keeping the change visible beside other custom rules.

Back up the file, place the directive outside WordPress markers and test both a directory URL and a known asset. The absence of a listing should not interrupt normal media delivery.

The editor cannot make public files confidential or override a host that forbids Optionsin .htaccess. Use server policy or protected storage for those requirements.

Explore AIOWS Htaccess EditorCompare AIOWS plans

Conclusion and recommended route

Disable Apache indexes at the correct scope and verify that direct assets still work. Then remove sensitive files from public storage, because hiding the filename list is only one layer of protection.

Official sources

Related Posts

Get All in One WP SettingsGet Plugin