Deindexing pages in Next.js and static sites
With frameworks and static generators, nothing is toggled in a dashboard. You set noindex in code, headers in config, and status codes in hosting rules. That gives you precise control, and makes it easy to ship the wrong rule to production.
Next.js App Router: the Metadata API
In the App Router, set robots metadata with the generateMetadata and metadata exports. For a page that should be excluded:
// app/thank-you/page.js
export const metadata = {
robots: {
index: false,
follow: true,
},
};
Next.js renders this as a robots meta tag in the head. For dynamic routes, use generateMetadata and return a robots object based on the data, for example hiding items flagged as unpublished or expired. Confirm in the output HTML that the tag is present in the initial response and not only after hydration.
Pages Router
In the Pages Router, add the tag in the page's head with the next/head component:
<Head>
<meta name="robots" content="noindex" />
</Head>
Server-render or statically generate the page, so the tag is in the initial HTML.
Sending X-Robots-Tag in next.config
For file types, path patterns or a whole host, set a response header with the headers option in next.config.js:
// next.config.js
module.exports = {
async headers() {
return [
{
source: '/downloads/:path*',
headers: [{ key: 'X-Robots-Tag', value: 'noindex' }],
},
];
},
};
Headers defined this way apply to responses served by Next.js. If you deploy behind a CDN that overrides headers, or export a fully static site, use the hosting platform's header configuration instead. See the X-Robots-Tag guide.
Static site generators and hosts
The same principle applies to Hugo, Jekyll, Eleventy, Astro and plain HTML: emit a robots meta tag from a template or front matter flag, and use host-level header rules for files.
| Where | Typical way to noindex |
|---|---|
| Template or layout | Output the meta tag when a front matter flag such as noindex: true is set |
| Netlify-style hosting | A headers file or config rule for paths |
| Cloudflare Pages-style hosting | A headers file with per-path rules |
| Vercel-style hosting | Headers in the project configuration |
| Apache or Nginx | Directives shown in the header guide |