Skip to content

Canonical URLs

A canonical URL tells search engines which version of a page is the “official” one. This prevents duplicate content issues when the same content is accessible from multiple URLs.

Duplicate content confuses search engines. Consider these URLs that all show the same product:

  • https://shop.com/products/123
  • https://shop.com/products/123?ref=homepage
  • https://shop.com/products/123?color=red
  • https://shop.com/en/products/123

Without a canonical URL, search engines see four different pages with the same content. They may split ranking signals across all four, or pick the wrong one. The canonical URL tells them which one to treat as the original.

app/products/[slug]/page.tsx
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const product = await getProduct(params.slug)
return {
title: product.title,
alternates: {
canonical: `https://shop.com/products/${product.slug}`,
},
}
}
app/products/[slug]/page.tsx
export async function generateMetadata(
{ params, searchParams }: Props
): Promise<Metadata> {
return {
alternates: {
// Always point to the base URL without query parameters
canonical: `https://shop.com/products/${params.slug}`,
},
}
}
ScenarioCanonical URL
Same content, different URLsPoint to the main URL
Query parameter variations (sort, filter)Point to the base page
www vs non-wwwChoose one and set it as canonical
HTTP vs HTTPSUse the HTTPS version
Paginated contentEach page is its own canonical
Syndicated contentPoint back to the original source
app/blog/page/[page]/page.tsx
export async function generateMetadata({ params }: Props): Promise<Metadata> {
return {
alternates: {
canonical: `https://myblog.com/blog/page/${params.page}`,
},
}
}
  • Not setting canonical URLs — Every page with multiple access paths needs a canonical.
  • Setting different canonical URLs for the same content — Be consistent.
  • Canonical to non-existent pages — The canonical URL must resolve to a real page.
  • Forgetting about query parameters — Tracking params (utm_source, ref) create duplicate URLs.
  • Every page should have a self-referencing canonical URL
  • Use alternates.canonical in the Metadata API
  • Strip query parameters from the canonical URL
  • Be consistent across your entire site
  • Test with Google’s URL Inspection tool

Canonical URLs prevent duplicate content issues by telling search engines which version of a page is the official one. Set them via the Metadata API’s alternates.canonical and always point to the cleanest version of the URL without tracking parameters.