Platforms

AI SEO on Next.js: robots.ts, AI crawlers and JSON-LD

In the Next.js App Router, robots.txt is code, which makes it easy to get exactly right and just as easy to get wrong.

robots.ts

Add app/robots.ts (or a static app/robots.txt). It returns a Robots object, and rules can be an array so each crawler gets its own group:

import type { MetadataRoute } from 'next'

export default function robots(): MetadataRoute.Robots {
  return {
    rules: [
      { userAgent: '*', allow: '/' },
      // Allow AI search; opt out of OpenAI and Anthropic training.
      { userAgent: ['OAI-SearchBot', 'Claude-SearchBot', 'PerplexityBot'], allow: '/' },
      { userAgent: ['GPTBot', 'ClaudeBot'], disallow: '/' },
    ],
    sitemap: 'https://example.com/sitemap.xml',
  }
}

Next.js writes one User-Agent group per entry. A crawler named in its own group ignores the * group, so be explicit about anything you block. Brave's crawler, which powers Claude's web search, has no name of its own and follows your Googlebot rules.

How do you check what your Next.js site allows?

Environment-specific code is a common trap: a disallow: '/' meant for preview deployments that ends up in production. After deploying, run the live site through our AI crawler checker, and look up any crawler in the AI crawler directory.

Server-render your content

AI crawlers and search engines read the HTML your server sends. Content that only appears after client-side JavaScript runs may not be seen. Server Components and static rendering, the App Router's defaults, avoid that.

JSON-LD

Render a <script type="application/ld+json"> in the page or layout with your Organization, LocalBusiness or SoftwareApplication data. Our schema generator writes the JSON for you.

Sources

Free AI visibility audit

What's your website?

We'll check how AI assistants talk about it and email you what we find.

You'll hear back from Ricardo, the founder, within one business day.