Do not disallow assets that a page needs to render
If Google cannot fetch important styles or scripts, it may not understand the page correctly.
Generate robots.txt in the Next.js App Router, add crawler-specific rules safely, and test the live route and indexing behavior.
For the Next.js App Router, put a static robots.txt in app/ or generate it with app/robots.ts returning MetadataRoute.Robots. The generated route is cached by default. Use robots.txt to manage crawl access, not to hide a page from Google: a blocked URL may still appear in results, while noindex requires the crawler to fetch the page.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
app/robots.txt as a static file and app/robots.ts as a generated metadata route. Use the static file when crawler rules are stable. Use TypeScript when the sitemap URL or rule set must be generated from application configuration. Next.js exposes the result at /robots.txt. The robots file convention was introduced in Next.js 13.3.0, and the other field for non-standard directives such as Yandex Clean-param arrived in 16.3.0.Replace the example host with the production canonical host and keep paths as root-relative prefixes. MetadataRoute.Robots accepts one rules object or an array of bot-specific rules, plus sitemap and host fields. A generated robots.ts route is cached by default unless you opt into request-time behavior or dynamic configuration.
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
disallow: ['/private/', '/preview/'],
},
sitemap: 'https://example.com/sitemap.xml',
}
}/private/ is not blocked for it. Repeat shared rules in each group, and check the documentation of each crawler you target.If Google cannot fetch important styles or scripts, it may not understand the page correctly.
Use deployment configuration and access controls for private previews; a robots rule alone is not authentication.
Point to the deployed canonical sitemap path.
Google says robots.txt rules apply only to the host, protocol, and port where the file is hosted, so rules at example.com do not govern a separate subdomain.
Google enforces a 500 KiB limit and ignores content after it. It generally caches robots.txt for up to 24 hours, so a change is not instant.
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return {
rules: [
{ userAgent: '*', allow: '/', disallow: '/private/' },
{ userAgent: 'Googlebot', allow: '/', disallow: '/preview/' },
],
sitemap: 'https://example.com/sitemap.xml',
}
}noindex directive, or protect the page with authentication.Disallownoindex meta tag or X-Robots-TagVisit https://example.com/robots.txt on the production hostname. Confirm it returns the intended plain-text rules and sitemap URL.
Confirm which file produces the live output: app/robots.txt, app/robots.ts, or in a Pages Router app public/robots.txt. A CDN or proxy can also serve a different response, so inspect the actual response instead of trusting the source file alone.
Check that an important page is allowed, a private or preview path is blocked if intended, and required assets remain available to crawlers.
Use URL Inspection in Search Console to see how Google treats a specific page. Crawl access and indexing are different questions: an allowed URL is not necessarily indexed.
If rules depend on environment variables or deployment mode, check production after publishing. The generated route's default cache behavior means runtime changes may not appear until its cache conditions are addressed.
For the corresponding sitemap route, see Next.js XML sitemap and the Next.js redirects guide. For Google-specific behavior, read the robots.txt glossary and Googlebot guide.
3 questions people ask next, answered from the sources on this page.
For the App Router, add app/robots.txt for static rules or app/robots.ts that returns MetadataRoute.Robots for generated rules.
Next.js documents the generated robots route as cached by default. Check the production response and whether your implementation uses request-time APIs or dynamic configuration.
Not reliably. Google can index a blocked URL it discovers elsewhere. To keep a public page out of results, let Google crawl it and read a noindex directive, or require authentication for private content.
Run the free audit, then approve the fixes. Every change can be undone.