Fixing the most common Next.js SEO issues
Noindex in metadata
A robots field in a layout applies to every page below it:
export const metadata = {
robots: { index: true, follow: true },
};Check for environment-based switches too. A preview-only noindex is good; one that fires on production is not. More in how to remove a noindex tag.
X-Robots-Tag from headers or middleware
Search next.config headers(), middleware and your host’s config for X-Robots-Tag. See X-Robots-Tag explained.
robots.txt and sitemap
// app/robots.ts
export default function robots() {
return {
rules: { userAgent: '*', allow: '/', disallow: '/api/' },
sitemap: 'https://example.com/sitemap.xml',
};
}Add app/sitemap.ts returning your indexable URLs. If pages change often, make sure the sitemap is regenerated on deploy rather than cached from an old build.
Canonicals and titles
// app/layout.tsx
export const metadata = {
metadataBase: new URL('https://example.com'),
title: { default: 'Example', template: '%s | Example' },
};
// app/pricing/page.tsx
export const metadata = {
title: 'Pricing',
description: 'Plans and prices for Example.',
alternates: { canonical: '/pricing' },
};A title template keeps every page unique without repeating the brand by hand. See canonical mistakes.
H1 and images
Render one <h1> per page, usually in the page component rather than a shared layout. Give every next/image a meaningful alt, or alt="" for decorative images.
Client-only content
Content that appears only after client-side data fetching may be missing from the HTML the checker reads first. Render important text and metadata on the server.
Frequently asked questions
Why check the deployed site instead of the code?
Environment variables, middleware, hosting headers and layouts can all change what is served. The checker reads the real response, including headers that never appear in your source.
My production site is noindexed. What should I check first?
Search for robots: { index: false } in metadata exports and layouts, for X-Robots-Tag in next.config headers and middleware, and for environment checks that decide whether the site counts as production.
How do I add a sitemap in the App Router?
Add app/sitemap.ts that exports a function returning your URLs, or a route handler that returns XML. Next.js serves it at /sitemap.xml.
How do I set canonical URLs?
Set metadataBase in the root layout and alternates.canonical in each page metadata export, so every page gets an absolute canonical URL.
