Services built by a real sysadmin.

Every product in this shop was tested in production, optimized under pressure, and designed to make your infrastructure safer, faster, and cleaner.

Browse services

Serve WP Rocket Cache Directly via Apache – Rocket-Nginx Style

wp rocket apache rewrite rules

If you’re using WP Rocket and want to drastically improve performance, one of the best tricks is to bypass WordPress and PHP entirely when a static cache file exists. While Rocket-Nginx offers this for NGINX servers, Apache users can achieve the same result using smart .htaccess rules.

Here’s how to do it.


The Problem

By default, WP Rocket cache is generated into:

wp-content/cache/wp-rocket/your-domain.com/

But Apache doesn’t know to check there first. So every request, even if cached, still hits WordPress and PHP — wasting resources.


The Solution: .htaccess Rewrite Rules

You can use .htaccess to check if a static cached file exists and serve it immediately, skipping WordPress completely.

Add this to your root .htaccess file:

<IfModule mod_mime.c>
  AddEncoding gzip .html_gzip
  AddType text/html .html_gzip
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.html_gzip$">
    Header set Content-Encoding gzip
    Header set Content-Type "text/html; charset=UTF-8"
  </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Define cache folder
  RewriteCond %{HTTP_HOST} ^(www\.)?(.+)$ [NC]
  RewriteRule .* - [E=HOST:%2]

  # Serve gzipped cache if supported and exists
  RewriteCond %{REQUEST_METHOD} GET
  RewriteCond %{HTTP_COOKIE} !(comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in) [NC]
  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index-https.html_gzip -f
  RewriteRule .* /wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index-https.html_gzip [L]

  # Serve HTTPS non-gzipped cache if exists
  RewriteCond %{HTTPS} on
  RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index-https.html -f
  RewriteRule .* /wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index-https.html [L]

  # Serve HTTP gzipped cache if supported and exists
  RewriteCond %{REQUEST_METHOD} GET
  RewriteCond %{HTTP_COOKIE} !(comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in) [NC]
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index.html_gzip -f
  RewriteRule .* /wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index.html_gzip [L]

  # Serve HTTP non-gzipped cache if exists
  RewriteCond %{HTTPS} off
  RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index.html -f
  RewriteRule .* /wp-content/cache/wp-rocket/%{ENV:HOST}/%{REQUEST_URI}/index.html [L]
</IfModule>

Result

With these rules:

  • Visitors get blazing fast static HTML delivery
  • WordPress and PHP are completely bypassed if cache exists
  • Resource usage drops and TTFB improves dramatically

This is the closest you can get to Rocket-Nginx behavior on Apache, with zero plugins or server-level modules required.

Need Expert Help?

If you’re still having issues with your server or network setup, let’s fix it together. Schedule a one-on-one consultation now.

Schedule a Consultation

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *