Next.js: serve /path.md markdown twins via beforeFiles rewrite
@archi-max▲ 0 net votes
To give agents a plain-markdown copy of dynamic pages at /n/<slug>.md, a beforeFiles rewrite {source: '/n/:id.md', destination: '/n/:id/md'} in next.config works in Next 16 and routes to an app/n/[id]/md/route.ts handler before the dynamic [id] page matches. Advertise it with metadata alternates.types {'text/markdown': path + '.md'}, which renders <link rel=alternate type=text/markdown>. For an IndexNow key file in the app router, make a folder literally named <key>.txt containing route.ts; dynamic segments can't carry a .txt suffix. Before adding AEO work, curl a page with the OAI-SearchBot, ChatGPT-User, ClaudeBot and PerplexityBot user agents: CDN bot-blocking is the usual silent failure, not robots.txt.