A page rendered by a layout or page file
- Use
metadata.robotsorgenerateMetadata- Why
- Sets a robots meta tag in the page head.
Noindex Next.js pages with the metadata robots option or an X-Robots-Tag header in next.config.js, avoid robots.txt conflicts, and verify the live output.
In the Next.js App Router, export metadata with a robots object from a layout or page to set the robots meta tag; use index: false for noindex and confirm the rendered tag on your build. For PDFs and other non-HTML files, return an X-Robots-Tag: noindex header from headers() in next.config.js. Don't block the URL in robots.txt: Google has to crawl the page to see the rule.
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.
metadata.robots or generateMetadataX-Robots-Tag in headers()X-Robots-Tag in headers() with a source pattern<meta name="robots" content="noindex" /> for pages that return a 404 status code.Google says the meta tag and the header have the same effect, so choose the one that fits the content type. Both are read only when Googlebot crawls the page: when it extracts the rule, Google drops the page entirely from Search results, regardless of whether other sites link to it.
Next.js documents the robots field with index: true and follow: true outputting <meta name="robots" content="index, follow" />. The docs page doesn't show the output for index: false, so confirm on your own build, with the check below, that the example renders a noindex value. For a condition that depends on data, return the same object from generateMetadata.
import type { Metadata } from 'next'
export const metadata: Metadata = {
robots: {
index: false,
follow: false,
},
}
export default function Page() {
return <h1>Internal page</h1>
} source is the incoming request path pattern. /internal/:path* matches /internal and every nested path, because * means zero or more.
Headers are checked before the filesystem, which includes pages and /public files.
If two header rules match the same path and set the same key, the last one overrides the first. Keep one X-Robots-Tag rule per path to avoid surprises.
Google lets an X-Robots-Tag start with a user agent, for example googlebot: nofollow, and allows none as a value equivalent to noindex, nofollow.
module.exports = {
headers() {
return [
{
source: '/internal/:path*',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex',
},
],
},
]
},
}robots setting in a root layout applies to every route that doesn't override it. Read the noindex glossary entry and audit your layouts.# Meta tag in the HTML
curl -s https://example.com/internal | grep -i 'name="robots"'
# Header on the response
curl -sI https://example.com/internal | grep -i x-robots-tagRun the commands against the deployed site, not localhost, so any CDN or proxy rule is included.
To see the HTML Googlebot received while crawling the page, use the URL Inspection tool in Search Console.
Google says the Page Indexing report in Search Console shows pages from which Googlebot extracted a noindex rule.
3 questions people ask next, answered from the sources on this page.
Export metadata with robots: { index: false } from the page or layout, or send an X-Robots-Tag: noindex header using headers() in next.config.js. Don't disallow the URL in robots.txt.
Yes. Next.js injects <meta name="robots" content="noindex" /> for pages that return a 404 status code, including global-not-found.js pages.
Use the header method. Google says an X-Robots-Tag response header can be used for non-HTML resources such as PDFs, video files, and image files.
Run the free audit, then approve the fixes. Every change can be undone.