{"slug": "markdown-copies-of-pages-for-agents-without-hurting-seo", "title": "Markdown Copies Of Pages For Agents Without Hurting SEO", "summary": "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.", "body_md": "# Markdown Copies Of Pages For Agents Without Hurting SEO\n\n[Jake Marsh](https://deallocatedobjects.com/about)\n\n## In this post\n\nWhen 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.\n\nSo 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.\n\n## The Three Headers[#](#the-three-headers)\n\nHere’s a Markdown copy on this blog:\n\n**`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.\n\n**`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.\n\nGoogle’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.\n\n**`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.\n\nOne 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.”\n\n## In nginx[#](#in-nginx)\n\nThe 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:\n\nThe `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.\n\nThat’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.\n\n## In Next.js[#](#in-next-js)\n\nIn 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):\n\nThe same app also sent a sitewide `Link` header from `next.config.ts`, pointing agents at `llms.txt` and the sitemap:\n\nWith both in place, the `.md` responses came back with the discovery `Link` and no canonical. The route’s `Link` never reached the client.\n\n## How Next Combines Them[#](#how-next-combines-them)\n\nThe [`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.\n\nConfig 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):\n\nSo 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:\n\nThat’s the output after the fix, which is to keep the config rule off the `.md` paths with a negative lookahead in `source`:\n\nIf 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:\n\nRookiefeed’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.\n\n## Vary On The HTML Side[#](#vary-on-the-html-side)\n\n`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.\n\nHow 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:\n\n## Checking Your Own[#](#checking-your-own)\n\nWhatever the stack, the check is three requests:\n\nThe 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.", "url": "https://wpnews.pro/news/markdown-copies-of-pages-for-agents-without-hurting-seo", "canonical_source": "https://deallocatedobjects.com/posts/markdown-copies-of-pages-for-agents-without-hurting-seo", "published_at": "2026-11-28 14:00:00+00:00", "updated_at": "2026-11-28 14:11:42.233357+00:00", "lang": "en", "topics": ["ai-crawlers", "generative-engine-optimization", "ai-search", "developer-tools"], "entities": ["Jake Marsh", "Google", "nginx", "Next.js", "Rookiefeed"], "also_reported_by": [], "takeaway": "Serve Markdown copies with Link rel=\"canonical\" to the HTML page, X-Robots-Tag: noindex, follow, and Vary: Accept, and re-include shared header snippets inside any nginx location that adds its own add_header, since inheritance is dropped once a location defines one.", "recommendation": {"advice": "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.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/markdown-copies-of-pages-for-agents-without-hurting-seo", "markdown": "https://wpnews.pro/news/markdown-copies-of-pages-for-agents-without-hurting-seo.md", "text": "https://wpnews.pro/news/markdown-copies-of-pages-for-agents-without-hurting-seo.txt", "jsonld": "https://wpnews.pro/news/markdown-copies-of-pages-for-agents-without-hurting-seo.jsonld"}}