Skip to content

Commit 25e5ecd

Browse files
TBarregrenclaude
andcommitted
Prevent page caches from storing content-negotiation redirect
Full-page caches (LiteSpeed Cache, WP Super Cache, etc.) ignore the Vary: Accept header and cache the 303 redirect keyed by URL alone, causing all visitors to be redirected to the .md URL. Add three cache-prevention layers before the redirect: - DONOTCACHEPAGE constant (universal WP cache convention) - Cache-Control: private, no-store (HTTP standard for proxies/CDNs) - litespeed_control_set_nocache action (LSCWP API, no-op if inactive) The .md URLs themselves remain fully cacheable. Fixes #30 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 15738a8 commit 25e5ecd

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/Router/RewriteHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ public function handle_accept_negotiation(): void {
372372
return;
373373
}
374374

375+
// Prevent page caches from storing this content-negotiation redirect.
376+
// LiteSpeed Cache (and similar full-page caches) ignore the standard
377+
// HTTP Vary header and would serve this 303 to every visitor regardless
378+
// of their Accept header value.
379+
if (!defined('DONOTCACHEPAGE')) {
380+
define('DONOTCACHEPAGE', true);
381+
}
382+
header('Cache-Control: private, no-store');
383+
do_action('litespeed_control_set_nocache', 'Content negotiation redirect');
384+
375385
// 303 See Other: redirect to markdown URL with Vary for cache correctness.
376386
header('Vary: Accept');
377387
wp_safe_redirect($md_url, 303);

0 commit comments

Comments
 (0)