# Markdown Copies Of Pages For Agents Without Hurting SEO

> Source: <https://deallocatedobjects.com/posts/markdown-copies-of-pages-for-agents-without-hurting-seo>
> Published: 2026-11-28 14:00:00+00:00

**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 the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

# Markdown Copies Of Pages For Agents Without Hurting SEO

[Jake Marsh](https://deallocatedobjects.com/about)

## In this post

When I [made this blog readable by agents](https://deallocatedobjects.com/posts/making-my-blog-readable-by-ai-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[#](#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](https://developers.google.com/search/docs/crawling-indexing/consolidate-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](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag) 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](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag) say blocked URLs have their rules “ignored.”

## In nginx[#](#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](https://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header), `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](https://www.rfc-editor.org/rfc/rfc8288#section-3) defines `Link` as a comma-separated list, so two lines mean the same thing as one line with both values.

## In Next.js[#](#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](https://rookiefeed.com/?ref=deallocated-post):

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[#](#how-next-combines-them)

The [`headers()` docs](https://nextjs.org/docs/app/api-reference/config/next-config-js/headers) 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`](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/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](https://runheed.com/?ref=deallocated-post) 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-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[#](#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.
