---
title: Protect Cache Directory
description: "Learn how Powered Cache protects its WordPress cache folder from directory listing and direct access to logged-in user cache files, and what Nginx needs."
url: "https://poweredcache.com/docs/protect-cache-directory/"
updated: "2026-12-02"
category: Cache Rules
---

# Protect Cache Directory

The cache folder holds saved copies of your pages. With [Logged-in User Cache](/docs/page-caching/#logged-in-user-cache) on, it also holds a separate copy for each logged-in user, which can contain names, emails or account details. Powered Cache protects this folder on Apache and LiteSpeed automatically. On Nginx, you add one rule yourself.

**Available in:** Powered Cache (free)
**Where to find it:** there is no setting. Powered Cache writes the file `wp-content/cache/.htaccess` automatically.

## What Powered Cache does

Powered Cache writes this `.htaccess` file into the cache folder:

```
<IfModule mod_autoindex.c>
 Options -Indexes
</IfModule>

<FilesMatch "^.*-user_.*.(html|html.gz)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>
```

- **No directory listing:** nobody can browse the folder to see which pages are cached.
- **No direct access to logged-in user copies:** files whose names contain `-user_` cannot be downloaded by URL. Powered Cache itself still serves each copy to its own user, because it reads the file on the server, not through a URL.

Normal cached pages are the same public pages every visitor sees, so they are not blocked. The `meta.php` file saved next to each cached page starts with an `exit` line, so opening it by URL returns nothing.

The file is written again every time you save the Powered Cache settings, use **Regenerate Configuration** in Powered Cache → Tools, or activate the plugin. If you use the `POWERED_CACHE_CACHE_DIR` constant to move the cache folder, the file goes into that folder. See [wp-config Constants](/docs/wp-config-constants/).

## After Purge All Cache

**Purge All Cache** deletes the whole cache folder, including this `.htaccess` file. Powered Cache creates the folder again on the next visit, but the protection file only comes back the next time the configuration is written. If you use Logged-in User Cache, click **Regenerate Configuration** in Powered Cache → Tools, or save the settings, after using Purge All Cache. See [Clear Cache](/docs/clear-cache/) and [Fix Configuration](/docs/fix-configuration/).

## Apache and LiteSpeed

No action is needed. Apache and LiteSpeed read the file as long as the server allows `.htaccess` overrides, which is the normal setup for WordPress. The deny rule uses the older `Order` and `Deny` syntax, which Apache 2.4 supports through its `mod_access_compat` module.

## Nginx

Nginx ignores `.htaccess` files, so the file has no effect there. Directory listing is off in Nginx unless someone turned on `autoindex`. If you use Logged-in User Cache, block the per-user files by adding this to your site's `server` block:

```
location ~* ^/wp-content/cache/powered-cache/.*-user_.*.html(.gz)?$ {
    deny all;
}
```

Adjust the path if you moved the cache folder. Ask your host to add the rule if you cannot edit the Nginx configuration. Without Logged-in User Cache, there are no per-user files and you do not need the rule.

## Check the protection

1. Open `https://example.com/wp-content/cache/powered-cache/` in a browser, with your own domain. You should get a *403 Forbidden* or *404 Not Found* error, not a list of folders.
2. If you see a list of folders on Apache, check that `wp-content/cache/.htaccess` exists. If it is missing, click **Regenerate Configuration** in Powered Cache → Tools.

## For developers

The `powered_cache_cache_dir_htaccess_file_content` filter changes the contents of the file, for example to use the Apache 2.4 `Require all denied` syntax. Save the settings after adding the filter. See the [hook reference](https://poweredcache.github.io/docs/).

## Related docs

- [Server Configuration](/docs/server-configuration/)
- [Logged-in User Cache](/docs/page-caching/#logged-in-user-cache)
- [Fix Configuration](/docs/fix-configuration/)
- [wp-config Constants](/docs/wp-config-constants/)
