From 1cb8701a35de7a1392ed734665cfc8c38b1858ef Mon Sep 17 00:00:00 2001 From: Jack Arturo Date: Mon, 15 Jun 2026 18:41:26 +0200 Subject: [PATCH] fix(theme): serve /llms.txt without trailing-slash redirect WordPress's canonical redirect was 301-ing /llms.txt -> /llms.txt/, which AI crawlers don't expect (robots.txt-style files serve at the exact path). Disable redirect_canonical for the llms route, accept an optional trailing slash in the rewrite, and run the handler at priority 0 (before canonical). Co-Authored-By: Claude Opus 4.8 (1M context) --- functions.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index 10f1d34..2db137e 100644 --- a/functions.php +++ b/functions.php @@ -473,7 +473,13 @@ function minimalcode_maybe_flush_after_deploy() { * hooks above, same as the virtual routes. */ add_action('init', function () { - add_rewrite_rule('^llms\.txt$', 'index.php?minimalcode_llms=1', 'top'); + add_rewrite_rule('^llms\.txt/?$', 'index.php?minimalcode_llms=1', 'top'); +}); + +// Serve /llms.txt at the exact path (like robots.txt) — WordPress's canonical +// redirect would otherwise 301 it to /llms.txt/, which AI crawlers don't expect. +add_filter('redirect_canonical', function ($redirect_url) { + return ('1' === (string) get_query_var('minimalcode_llms')) ? false : $redirect_url; }); add_filter('query_vars', function ($vars) { @@ -511,5 +517,5 @@ function minimalcode_maybe_flush_after_deploy() { header('Content-Type: text/plain; charset=utf-8'); echo implode("\n", $lines) . "\n"; exit; -}); +}, 0);