---
title: Server Configuration
description: "Set up Apache, LiteSpeed or Nginx for Powered Cache in WordPress: what the automatic .htaccess rules do and what Nginx users need to configure by hand."
url: "https://poweredcache.com/docs/server-configuration/"
updated: "2026-12-02"
category: Cache Rules
---

# Server Configuration

Powered Cache serves cached pages through PHP on every web server, without extra setup. On Apache and LiteSpeed it can also write rules to your `.htaccess` file, so the web server sends cached pages directly without starting PHP, and adds browser caching and compression. On Nginx, you add such rules to the server configuration yourself.

**Available in:** Powered Cache (free)
**Where to find it:** Powered Cache → Advanced → **.htaccess Configuration**
**Requires:** Apache or LiteSpeed for the automatic rules, and a writable `.htaccess` file in the WordPress root folder.

![](data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=)

## How cached pages are served

| Server | Without server rules | With server rules |
| --- | --- | --- |
| Apache, LiteSpeed | PHP sends the cached file (`X-Powered-Cache: PHP`). | The web server sends the cached file (`X-Powered-By: Powered Cache`). Written automatically by .htaccess Configuration. |
| Nginx | PHP sends the cached file (`X-Powered-Cache: PHP`). | Nginx sends the cached file (`X-Powered-Cache: nginx`). You add the rules by hand. |

Serving through PHP is already fast, because WordPress, plugins and the database are not loaded. Server rules make it a little faster again and save PHP workers on busy sites. See [Check Cache Status](/docs/check-cache-status/#response-headers) to see which way a page was served.

## .htaccess Configuration (Apache and LiteSpeed)

Lets Powered Cache write recommended rules to the `.htaccess` file in your WordPress root folder. **Default: on** when WordPress detects Apache or LiteSpeed, **off** on other servers. Keep it on unless your host manages `.htaccess` for you.

The rules go into one block at the top of the file, between `# BEGIN POWERED CACHE` and `# END POWERED CACHE`. Powered Cache rewrites this block every time you save the settings or use **Regenerate Configuration**. Lines outside the block are not changed.

### What the rules do

- **Serve cached pages directly.** Apache sends the cached file when the request is not a `POST`, has no query string, matches your permalink trailing slash, does not come from a rejected user agent or from `facebookexternalhit`, has no rejected cookie (including the WordPress login and comment cookies), and a cached file exists. HTTPS, [Separate Mobile Cache](/docs/page-caching/#separate-mobile-cache) and [Gzip Compression](/docs/page-caching/#gzip-compression) are taken into account.
- **Browser caching** (`mod_expires`): browsers keep static files for a while instead of downloading them on every visit. HTML, XML and JSON are not kept.
- **Compression** (`mod_deflate`): HTML, CSS, JavaScript, JSON, XML, SVG and font files are compressed on the way out.
- **Headers for cached HTML files:** `X-Powered-By: Powered Cache` and `Cache-Control: public`. ETag headers are removed.
- **CORS headers** for images and fonts, when the [CDN integration](/docs/cdn-integration/) is on, so fonts load from your CDN hostname.
- **The `/_static/` rewrite**, when [File Optimizer Rewrite Rules](/docs/file-optimizer-rewrite-rules/) is on.

| File type | Browser cache lifetime |
| --- | --- |
| CSS and JavaScript | 1 year |
| JPEG, PNG, GIF, WebP, BMP, TIFF and HEIC images | 6 months |
| SVG images and font files | 4 months |
| Favicon | 1 week |
| RSS and Atom feeds | 1 hour |
| HTML, plain text, XML and JSON | Not cached by the browser |

Long lifetimes for CSS and JavaScript are safe, because WordPress and Powered Cache add version strings to these URLs when the files change.

### What the server rules do not check

The web server checks fewer conditions than Powered Cache does in PHP:

- [Rejected Referrers](/docs/advanced-cache-rules/#rejected-referrers) are not checked.
- When [Mobile Cache](/docs/page-caching/#mobile-cache) is off, the rules do not detect mobile devices. Mobile visitors can still get the cached desktop page from the server.
- While [Vary Cookies](/docs/advanced-cache-rules/#vary-cookies) has any entry, including cookies added automatically for supported cookie consent plugins, Powered Cache leaves the direct-serving rules out. Browser caching and compression rules are still written. Cached pages are then served by PHP.

If you rely on one of the first two, turn .htaccess Configuration off and remove the Powered Cache block, as described below.

### Turning the rules off

- While .htaccess Configuration is on, the block is removed automatically when you turn off Page Cache or deactivate Powered Cache.
- Turning .htaccess Configuration **off** does not remove the block that is already in the file. Powered Cache simply stops updating it. To remove it, delete everything from `# BEGIN POWERED CACHE` to `# END POWERED CACHE` in `.htaccess`, or turn off Page Cache and save while the option is still on.

### Requirements and multisite

- The `.htaccess` file must exist and be writable. Otherwise the settings screen warns: *Automatic .htaccess configuration is enabled, but the .htaccess file could not be found* or *… is not writable*. Save your permalinks once in Settings → Permalinks to create the file, or ask your host to fix its permissions.
- On multisite, the network shares one `.htaccess` file. Powered Cache writes it only when the plugin is network-activated and a network administrator saves the settings. See [Multisite Setup](/docs/multisite-setup/).

> **Changed in 4.0:** Rejected User Agents in the `.htaccess` rules now match anywhere in the user agent, the same way as in PHP. Before 4.0, the server rules could treat them differently.

## LiteSpeed and OpenLiteSpeed

WordPress treats LiteSpeed as an Apache-compatible server. Powered Cache therefore offers .htaccess Configuration there and writes the same rules. Powered Cache has no separate LiteSpeed integration.

- Do not run the LiteSpeed Cache plugin's page cache at the same time. Two full-page caches make problems hard to trace, and the [Optimization Advisor](/docs/optimization-advisor/) warns about it. See [Other cache plugins](/docs/plugin-and-theme-compatibility/#other-cache-plugins).
- OpenLiteSpeed supports only part of the `.htaccess` syntax and may need a restart before it reads changes. If cached pages are not served directly there, Powered Cache still serves them through PHP. Ask your host if you are unsure.

## Nginx

Nginx does not read `.htaccess` files. Leave .htaccess Configuration off. The Optimization Advisor recommends this too.

Page caching works on Nginx without any change to the server configuration: cached pages are served through PHP. Most Nginx sites can stop here. Browser caching and compression for static files are usually set up by your host.

Powered Cache 4.1 does not show ready-made Nginx rules in its settings. If you manage your own server and want Nginx to send cached pages directly, add rules like the following to your site's `server` block. They are based on the rules Powered Cache generates internally. Replace the `try_files` line of your existing `location /` block instead of adding a second one, and test on a staging site first.

```
# Powered Cache: serve cached pages directly
set $pc_cache_uri $request_uri;
set $pc_ssl "";

if ($request_method = POST) { set $pc_cache_uri 'null cache'; }
if ($query_string != "") { set $pc_cache_uri 'null cache'; }
if ($https = "on") { set $pc_ssl "-https"; }

if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml)") {
    set $pc_cache_uri 'null cache';
}

if ($http_cookie ~* "wordpress_[a-f0-9]+|wordpress_logged_in_|wp-postpass|comment_author_|powered_cache_commented_posts") {
    set $pc_cache_uri 'null cache';
}

if ($http_user_agent ~* "facebookexternalhit") {
    set $pc_cache_uri 'null cache';
}

location / {
    add_header X-Powered-Cache nginx;
    try_files /wp-content/cache/powered-cache/$http_host/$pc_cache_uri/index${pc_ssl}.html $uri $uri/ /index.php?$args;
}
```

- If you use a custom cache folder or WordPress lives in a subfolder, adjust the path after `try_files`.
- Add your own [Rejected Cookies](/docs/advanced-cache-rules/#rejected-cookies) and [Rejected User Agents](/docs/advanced-cache-rules/#rejected-user-agents) to the matching lines.
- Do not use these rules together with Vary Cookies, Separate Mobile Cache, Rejected Referrers, or Mobile Cache turned off. Nginx cannot tell those visitors apart.
- With Gzip Compression on, Powered Cache saves only `.html.gz` files, so these rules find no file and every request goes to PHP. Leave Gzip Compression off and let Nginx compress responses.

Reload Nginx and check a logged-out page for `X-Powered-Cache: nginx`. If you use [File Optimizer Rewrite Rules](/docs/file-optimizer-rewrite-rules/), add the `/_static/` rule from that page as well. To keep logged-in user cache files private, see [Protect Cache Directory](/docs/protect-cache-directory/).

## Troubleshooting

### The site shows a server error after saving

Some hosts do not allow every directive in `.htaccess`. Connect with FTP or your host's file manager, open `.htaccess` in the WordPress root folder, and delete the block from `# BEGIN POWERED CACHE` to `# END POWERED CACHE`. Then turn off .htaccess Configuration and save. Your pages are still cached and served through PHP.

### Pages are never served directly by Apache

- Check that the Powered Cache block exists in `.htaccess` and that the server has `mod_rewrite`.
- Check that Vary Cookies is empty and no cookie consent plugin from the [supported list](/docs/advanced-cache-rules/#vary-cookies) is active.
- Test without a query string and while logged out.

## For developers

- `powered_cache_auto_htaccess_update`: return `false` to stop Powered Cache from writing `.htaccess`.
- `powered_cache_mod_rewrite`: return `false` to leave out the rules that serve cached pages directly.
- `powered_cache_browser_cache`, `powered_cache_browser_cache_lifespan`, `powered_cache_browser_cache_assets_lifespan` and `powered_cache_browser_cache_default_lifespan`: turn off or change the browser cache rules.
- `powered_cache_htaccess_add_cors`, `powered_cache_htaccess_cache_control_rules`, `powered_cache_pre_htaccess` and `powered_cache_after_htaccess`: change the CORS and Cache-Control rules, or add your own rules before or inside the block.

Save the settings after adding a filter so the block is written again. See the [hook reference](https://poweredcache.github.io/docs/).

## Related docs

- [Page Caching](/docs/page-caching/)
- [File Optimizer Rewrite Rules](/docs/file-optimizer-rewrite-rules/)
- [Protect Cache Directory](/docs/protect-cache-directory/)
- [Hosting Compatibility](/docs/hosting-compatibility/)
- [Check Cache Status](/docs/check-cache-status/)
