cd /news/ai-crawlers/markdown-copies-of-pages-for-agents-… · home › topics › ai-crawlers › article
[ARTICLE · art-177756] src=deallocatedobjects.com ↗ pub= topic=ai-crawlers verified=true sentiment=· neutral

Markdown Copies Of Pages For Agents Without Hurting SEO

Developer Jake Marsh documented a method for serving Markdown copies of blog pages to AI agents without harming search rankings by adding three HTTP response headers to each copy: a Link rel="canonical" header pointing to the HTML page, X-Robots-Tag: noindex, follow, and Vary: Accept. Marsh implemented the headers in nginx, where add_header directives are inherited only if no add_header is defined at the current level, and in Next.js, where a proxy rewrites .md requests to a route handler. Marsh warned against disallowing *.md in robots.txt, since Google ignores X-Robots-Tag and canonical rules on URLs it cannot fetch.

recommendation

When serving Markdown copies to agents, add canonical, noindex and Vary: Accept headers, and repeat shared nginx header includes inside any location that sets its own add_header.

more in playbook: Running AI in production
by read5 min views1 publishedNov 28, 2026
Markdown Copies Of Pages For Agents Without Hurting SEO
Image: Deallocatedobjects (auto-discovered)

Jake Marsh

In this post #

When I made this blog readable by agents, every post got a Markdown copy at its URL plus .md, and the normal URL answers with Markdown when a client sends Accept: text/markdown. Each HTML page also links its copy with <link rel="alternate" type="text/markdown">, so agents can find it.

So can search engines. Now every page exists twice with the same text, and the copy has no <head> to put a canonical tag in. The fix is three response headers on the copy. Getting them to reach clients took more care than I expected, especially in Next.js.

The Three Headers# #

Here’s a Markdown copy on this blog:

Link: <...>; rel="canonical" says the HTML page is the real one. Google supports the canonical as an HTTP header for exactly this case, documents that aren’t HTML, in its guide to duplicate URLs. Use an absolute URL there, as the same page asks. It also says to pick one place per URL, header or <link> element, since giving both invites them to disagree. A Markdown file has no element, so the header is the only choice anyway.

X-Robots-Tag: noindex, follow keeps the copy out of results. Google’s robots meta tag docs say the header form is how you noindex non-HTML resources. follow is already Google’s default (it follows links unless told nofollow); I spell it out so the intent is obvious to anyone reading the headers.

Google’s duplicate-URL guide does say it doesn’t recommend noindex for choosing a canonical, “because it will completely block the page from Search.” For the copy, blocking it completely is what I want. The canonical header still names the page that should rank.

Vary: Accept matters wherever one URL answers with HTML or Markdown depending on the request. Without it, a cache in the middle can store the Markdown and hand it to the next browser (or the reverse). The .md URL itself never negotiates, but sending Vary: Accept there is harmless, and on this blog it’s on every response.

One more thing: don’t disallow *.md in robots.txt to keep the copies out. Google only sees X-Robots-Tag and the canonical when it can fetch the URL, and its docs say blocked URLs have their rules “ignored.”

In nginx# #

The blog is static files behind nginx. A map turns the Accept header into a suffix, the post location rewrites to the .md file when it’s set, and the .md location adds the two headers:

The include line is the nginx gotcha. The shared snippet holds the security headers, Vary: Accept and the sitewide Link to llms.txt, and it’s included at the server level. But per the nginx docs, add_header directives are inherited “if and only if there are no add_header directives defined on the current level.” The moment this location adds its own canonical, every server-level header disappears from .md responses, so the location includes the snippet again.

That’s why the curl output above has two link: lines. nginx sends each add_header as its own line, and that’s fine: RFC 8288 defines Link as a comma-separated list, so two lines mean the same thing as one line with both values.

In Next.js# #

In a Next.js app, a proxy (Next 16’s name for middleware) rewrites /guides/foo.md, or /guides/foo with Accept: text/markdown and no text/html, to a route handler that returns the copy. This is from Rookiefeed:

The same app also sent a sitewide Link header from next.config.ts, pointing agents at llms.txt and the sitemap:

With both in place, the .md responses came back with the discovery Link and no canonical. The route’s Link never reached the client.

How Next Combines Them# #

The headers() docs only cover two config rules setting the same key: “the last header key will override the first.” They don’t say what happens when a config rule and a route handler set the same header, so I read the code.

Config headers are applied first. The router collects every matching rule into one object (resHeaders[key] = value, so a later rule replaces an earlier one) and calls res.setHeader for each before your route runs. Then send-response.ts copies your route’s Response headers onto that same response, like this (16.4.5, trimmed):

So for any header your config already set, the route’s value is skipped without a warning. Four names are exceptions and get appended. Link isn’t one of them, so the config’s Link stays and the route’s canonical is dropped. Vary is one of them, which is why the route’s Vary: Accept makes it through:

That’s the output after the fix, which is to keep the config rule off the .md paths with a negative lookahead in source:

If you still want the discovery links on the copies, have the route send them itself, in the same header as the canonical. Runheed does that: Rookiefeed’s config test now checks that the discovery rule matches /guides/how-much-does-mc-authority-cost and doesn’t match the .md version, so the exclusion can’t quietly go away.

Vary On The HTML Side# #

Vary has its own trap, on the HTML page rather than the copy. When /errors/econnreset negotiates, the HTML response needs Vary: Accept too, and setting it in the proxy isn’t enough. Next’s app-page handler runs after the proxy and calls res.setHeader('Vary', 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch'), and setHeader replaces whatever was there.

How much that matters depends on your cache headers. Rookiefeed’s pages are sent private, no-store, so nothing between the app and the browser keeps a copy. Runheed’s are s-maxage=31536000, which invites a shared cache to store them, so Runheed patches ServerResponse.prototype.setHeader and appendHeader from instrumentation.ts to add Accept to Vary on the negotiated paths, each token once:

Checking Your Own# #

Whatever the stack, the check is three requests:

The first two should carry the absolute canonical Link, X-Robots-Tag: noindex, follow and Accept in Vary. The third should be HTML, with Accept in Vary if the URL negotiates and your responses can be cached. Run them against the deployed site, since that’s the response where config, proxy and route headers all meet.

── more in #ai-crawlers 4 stories · sorted by recency
── more on @jake marsh 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/markdown-copies-of-p…] indexed:0 read:5min 2026-11-28 · —