Canonical URLs & Duplicate Content Prevention
Canonical URLs & Duplicate Content Prevention
Introduced in v0.1.61 — SEO control SEO-05 (
seo_meta_head)
What Are Canonical URLs?
A canonical URL is the single, authoritative address for a piece of content. When a page is reachable via multiple URLs — different domains, trailing-slash variants, query strings, or staging environments — the <link rel="canonical"> tag tells search engines which version to index and attribute ranking signals to.
Why This Matters
Without canonical links, Google may treat the following as separate pages with duplicate content:
https://calmony.com/andhttps://calmony.com(trailing slash)https://calmony.comandhttps://preview.calmony.com(staging domain)https://www.calmony.comandhttps://calmony.com(www vs. apex)
Duplicate indexing dilutes ranking signals and can suppress organic visibility.
Implementation
Canonical URLs are set via Next.js metadata exports using the alternates.canonical field.
Root Layout (src/app/layout.tsx)
The root layout declares the site-wide canonical:
export const metadata: Metadata = {
// ...other metadata
alternates: {
canonical: 'https://calmony.com',
},
};
This renders as:
<link rel="canonical" href="https://calmony.com" />
Page-Specific Canonicals
Each marketing page exports its own canonical URL to override the root-level default:
// src/app/privacy/page.tsx
export const metadata: Metadata = {
// ...other metadata
alternates: {
canonical: 'https://calmony.com/privacy',
},
};
Guidelines for New Pages
When adding any new public-facing page:
- Export a
metadataobject from the page file. - Always include
alternates: { canonical: '<full absolute URL>' }. - Use the production domain (
https://calmony.com) — never a relative path or staging domain. - For dynamic routes (e.g.
/blog/[slug]), generate the canonical programmatically:
export async function generateMetadata({ params }: Props): Promise<Metadata> {
return {
alternates: {
canonical: `https://calmony.com/blog/${params.slug}`,
},
};
}
Verification
After deployment, confirm canonical tags are rendered correctly by:
- Viewing page source and searching for
rel="canonical". - Using Google Search Console's URL Inspection tool.
- Running a crawl with a tool such as Screaming Frog or Ahrefs Site Audit.