0
0
NextJSframework~3 mins

Why Canonical URLs in NextJS? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how a simple link can boost your website's search ranking and avoid SEO headaches!

The Scenario

Imagine you have a website where the same page can be reached by multiple web addresses, like example.com/page and example.com/page?ref=123. You try to tell search engines which one is the main page by adding notes manually in every HTML file.

The Problem

Manually adding these notes is slow and easy to forget. Search engines might get confused and rank the wrong page, hurting your site's visibility. It's like telling different friends different addresses for the same party, causing confusion.

The Solution

Canonical URLs let you mark the main version of a page clearly in your code. Next.js helps you add these links automatically or easily, so search engines always know which page to show in search results.

Before vs After
Before
<link rel="canonical" href="https://example.com/page">  <!-- added manually in every page -->
After
import Head from 'next/head';

export default function Page() {
  return (
    <>
      <Head>
        <link rel="canonical" href="https://example.com/page" />
      </Head>
      {/* Page content here */}
    </>
  );
}
What It Enables

This makes your website SEO-friendly by preventing duplicate content issues and improving search engine rankings effortlessly.

Real Life Example

A blog with many tags and filters can have many URLs for the same article. Using canonical URLs tells Google which article URL is the main one, so readers find the right page easily.

Key Takeaways

Manually managing page versions is confusing and error-prone.

Canonical URLs clearly mark the main page for search engines.

Next.js makes adding canonical URLs simple and reliable.