Skip to content

fix(theme): serve /llms.txt without trailing-slash redirect#11

Merged
jack-arturo merged 1 commit into
mainfrom
fix/llms-txt-trailing-slash
Jun 15, 2026
Merged

fix(theme): serve /llms.txt without trailing-slash redirect#11
jack-arturo merged 1 commit into
mainfrom
fix/llms-txt-trailing-slash

Conversation

@jack-arturo

Copy link
Copy Markdown
Member

Follow-up to #10. /llms.txt was 301-redirecting to /llms.txt/ via WordPress's canonical redirect; AI crawlers expect a robots.txt-style file to serve at the exact path.

  • redirect_canonical filter returns false for the llms route (no trailing-slash redirect)
  • rewrite accepts optional trailing slash (^llms\.txt/?$)
  • handler runs at template_redirect priority 0 (before canonical)

Verified locally: php -l clean, static UI-marker test passes. Will confirm /llms.txt → 200 (no redirect) after deploy.

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 15, 2026 16:41
@jack-arturo jack-arturo merged commit ae95773 into main Jun 15, 2026
1 check passed
@jack-arturo jack-arturo deleted the fix/llms-txt-trailing-slash branch June 15, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures the theme serves /llms.txt directly (robots.txt-style) without WordPress canonical redirecting it to a trailing-slash variant, improving compatibility with AI crawlers that expect an exact-path response.

Changes:

  • Updates the rewrite rule to accept an optional trailing slash for the llms.txt route.
  • Disables redirect_canonical when serving the llms.txt virtual endpoint to prevent /llms.txt/llms.txt/ redirects.
  • Runs the llms.txt response handler earlier (template_redirect priority 0) so it executes before canonical redirect logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread functions.php
Comment on lines +479 to 483
// 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;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants