Skip to main content

Why PHP-Based Headers and Redirects Don’t Work with Cached Pages

Updated this week

FlyingPress generates static cached HTML pages to maximize performance. These pages are served directly by the web server (like Apache or Nginx), completely bypassing PHP execution.

As a result, any plugin or custom PHP code that expects to run on every request—such as those adding HTTP headers or redirection logic—will not work when a cached page is served.

Why this happens

  • Cached pages are served without loading PHP or WordPress.

  • This avoids unnecessary processing and improves performance.

  • But PHP-based logic like header() or wp_redirect() won’t be triggered.

Affected use cases

  • Redirections added via functions.php or plugins

  • Security headers added using PHP

  • Plugins like Really Simple SSL, which add headers or redirect to HTTPS using PHP logic

Note: These plugins still work for uncached requests or in the admin area. The limitation applies only to cached pages served as static files.

What to do instead

If you need headers or redirects to work consistently, apply them at the server or CDN level:

1. Web server configuration

Add rules before FlyingPress cache logic:

  • Apache/LiteSpeed (.htaccess)

    Header always set Strict-Transport-Security "max-age=31536000"
    Redirect 301 /old-page /new-page
  • Nginx

    add_header Strict-Transport-Security "max-age=31536000";
    rewrite ^/old-page$ /new-page permanent;

2. CDN (e.g., Cloudflare)

Use your CDN to:

  • Add HTTP security headers

  • Set up redirection rules

  • Apply geolocation or device-based routing

Did this answer your question?