Robots & Sitemap Checker

Guides › Platforms

Next.js: robots.ts and sitemap.ts (App Router)

In the App Router, add app/robots.ts and app/sitemap.ts. Next.js serves them at /robots.txt and /sitemap.xml.

// app/robots.ts
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
  return {
    rules: [
      { userAgent: '*', allow: '/', disallow: '/api/' },
      { userAgent: 'GPTBot', disallow: '/' },
    ],
    sitemap: 'https://example.com/sitemap.xml',
  }
}
// app/sitemap.ts
import type { MetadataRoute } from 'next'
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const posts = await getPosts()
  return [
    { url: 'https://example.com/', lastModified: new Date('2026-10-01') },
    ...posts.map(p => ({ url: 'https://example.com/blog/' + p.slug, lastModified: p.updatedAt })),
  ]
}

For more than 50,000 URLs, export generateSitemaps() to split the sitemap into several files. A static public/robots.txt also works but can't be dynamic. Don't keep both. Watch for preview deployments being indexed; Vercel adds X-Robots-Tag: noindex on preview URLs by default.

Check your site now

Related

WordPress robots.txt: default rules and how to editShopify robots.txt: how to edit robots.txt.liquid

More free tools from Swift Labs

OG Preview Tool
Preview links on Facebook, LinkedIn, X and Slack, and audit Open Graph tags.
Email DNS Check
Check SPF, DKIM, DMARC and MX records in seconds.
DeadLinkPatrol
Find broken links across your whole site.