# Next.js robots.txt

> Generate robots.txt in the Next.js App Router, add crawler-specific rules safely, and test the live route and indexing behavior.

Canonical: https://scaplet.com/seo/nextjs/robots-txt

Guide Next.js Next.js · Crawling

Generate robots.txt in the Next.js App Router, add crawler-specific rules safely, and test the live route and indexing behavior.

4 min

read

5

sources

Oct 24, 2026

updated

Scaplet Editorial Team

author

In one line

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.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Frobots-txt%20(%22Next.js%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Frobots-txt%20(%22Next.js%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Frobots-txt%20(%22Next.js%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Frobots-txt%20(%22Next.js%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 4 parts, 4 minutes.

1. [Choose static rules or a generated route 01](#choose-static-rules-or-a-generated-route)
2. [Add specific crawler rules only when needed 02](#add-specific-crawler-rules-only-when-needed)
3. [Crawl access is not indexing control 03](#crawl-access-is-not-indexing-control)
4. [Test the generated file after deployment 04](#test-the-generated-file-after-deployment)

_01_Check it

## Choose static rules or a generated route

The App Router recognizes `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.

app/robots.ts

```
import type { MetadataRoute } from 'next' export default function robots(): MetadataRoute.Robots { return { rules: { userAgent: '*', allow: '/', disallow: ['/private/', '/preview/'], }, sitemap: 'https://example.com/sitemap.xml', } }
```

_02_Worth knowing

## Add specific crawler rules only when needed

Most sites can keep one wildcard group. Next.js supports per-user-agent rules when you have a clear reason to treat a crawler differently. Be careful: Google says only one group is valid for a crawler, the one with the most specific matching [user agent](/glossary/user-agent), and other groups are ignored. In the example below, [Googlebot](/ai-crawlers/googlebot) follows its own group only, so `/private/` is not blocked for it. Repeat shared rules in each group, and check the documentation of each crawler you target.

### 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.

### Keep staging controls out of production by design

Use deployment configuration and access controls for private previews; a robots rule alone is not authentication.

### Avoid listing redirecting URLs in the sitemap line

Point to the deployed canonical sitemap path.

### Check the exact production hostname

Google says [robots.txt](/glossary/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.

### Keep the file small

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.

Separate Googlebot access from another crawler

```
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', } }
```

_03_Use the control that matches your goal

## Crawl access is not indexing control

Google states that robots.txt is not a mechanism for keeping a web page out of Google. A disallowed URL can still appear in results if other pages link to it, but the result will not have a description. If a public page must stay out of Google results, allow crawling and send a `noindex` directive, or protect the page with authentication.

Goal

### Reduce crawler requests to a path

Use

robots.txt `Disallow`

Important limit

A URL can still be indexed

Goal

### Keep a page out of Google results

Use

`noindex` meta tag or `X-Robots-Tag`

Important limit

Google must crawl the page to read the directive

Goal

### Keep private content private

Use

Authentication or access control

Important limit

Robots rules are public and not access protection

Goal

### Help crawlers find canonical URLs

Use

Sitemap and [internal links](/glossary/internal-links)

Important limit

Neither guarantees indexing

**Do not block a `noindex` page**If robots.txt disallows the page, Google cannot fetch its `noindex` tag. Remove the crawl block, deploy the directive, then verify the live response and let Google recrawl. Google does not support a `noindex` rule inside robots.txt itself.

_04_How it works

## Test the generated file after deployment

1. 1

### Open the public endpoint

Visit `https://example.com/robots.txt` on the production hostname. Confirm it returns the intended plain-text rules and sitemap URL.
2. 2

### Check for conflicting sources

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.
3. 3

### Test representative paths

Check that an important page is allowed, a private or preview path is blocked if intended, and required assets remain available to crawlers.
4. 4

### Check indexing separately

Use [URL Inspection](/glossary/url-inspection-tool) in [Search Console](/glossary/google-search-console) to see how Google treats a specific page. Crawl access and indexing are different questions: an allowed URL is not necessarily indexed.
5. 5

### Retest after config changes

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](/seo/nextjs/xml-sitemap) and the [Next.js redirects guide](/seo/nextjs/redirects). For Google-specific behavior, read the [robots.txt glossary](/glossary/robots-txt) and [Googlebot guide](/ai-crawlers/googlebot).

Questions

## Asked a lot.

3 questions people ask next, answered from the sources on this page.

_01_ Where do I put robots.txt in Next.js?

For the App Router, add `app/robots.txt` for static rules or `app/robots.ts` that returns `MetadataRoute.Robots` for generated rules.

_02_ Why is my Next.js robots.ts change not live?

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.

_03_ Can robots.txt stop a Next.js page from being indexed?

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.

Sources · 5

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- nextjs.org
- google.com

1. 01 [robots.txt | Next.js Documentation](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/robots) nextjs.org · checked 2026-10-24
2. 02 [Introduction to robots.txt | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/robots/intro) developers.google.com · checked 2026-10-24
3. 03 [How Google interprets the robots.txt specification | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt) developers.google.com · checked 2026-10-24
4. 04 [Block Search indexing with noindex | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/block-indexing) developers.google.com · checked 2026-10-24
5. 05 [Googlebot | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/googlebot) developers.google.com · checked 2026-10-24

## Keep learning

[All platform guides](/seo)

[Learn Next.js SEO Frameworks](/seo/nextjs) [Related robots.txt Crawling](/glossary/robots-txt) [Read next Next.js noindex Frameworks](/seo/nextjs/noindex) [Do Run a free site audit Free, about two minutes](/site-audit)

More in Next.js SEO
[Next.js 404 page](/seo/nextjs/404) [Next.js AI crawlers](/seo/nextjs/ai-crawlers) [Next.js canonical tags](/seo/nextjs/canonical-tags) [Next.js Google Analytics](/seo/nextjs/google-analytics) [Next.js image SEO](/seo/nextjs/image-seo) [Next.js lazy loading](/seo/nextjs/lazy-loading) [Next.js noindex](/seo/nextjs/noindex) [Next.js redirects](/seo/nextjs/redirects) [Next.js robots.txt](/seo/nextjs/robots-txt) [Next.js structured data](/seo/nextjs/structured-data) [Next.js title and meta description](/seo/nextjs/title-and-meta) [Next.js XML sitemap](/seo/nextjs/xml-sitemap)

Terms on this page
[User agent](/glossary/user-agent) [robots.txt](/glossary/robots-txt) [Internal links](/glossary/internal-links) [URL Inspection tool](/glossary/url-inspection-tool) [Google Search Console](/glossary/google-search-console)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
