If Search Console is showing "Duplicate without user-selected canonical" against pages on your Next.js + Sanity site, Google has found the same content at more than one URL and nobody told it which one to keep. Those pages are being dropped from the index, usually the ones you most want ranking. The cause is almost never Sanity itself. It is how routes, domains and metadata are wired in the frontend.
What the status actually means
Google crawls a URL, compares it to others it knows, and clusters near-identical pages. If your pages carry no canonical, or a canonical that points somewhere odd, Google chooses a winner on its own. Sometimes it picks the right one. Often it picks a vercel.app address, a URL with a query string, or the www version you stopped using two years ago.
There is a sibling status, "Duplicate, Google chose different canonical than user". That one means you did set a canonical and Google disagreed. The fixes below cover both, but that second status points harder at causes 3 and 4.
What it costs to ignore
Duplicates split link signals and crawl budget across URLs, and the version Google picks may be one with no internal links pointing at it. The practical result is landing pages that stay unindexed or rank under the wrong address, and analytics that blur together. It also tends to hide other problems, so it is worth ruling out before you chase anything else. If your pages are missing from the index for other reasons, see my notes on Next.js pages not indexed by Google.
Cause 1: no canonical, or a relative one with no metadataBase
The most common finding on inherited sites: the metadata API is used for titles and descriptions but nobody set a canonical. The second most common: a canonical was set as a relative path, but metadataBase is missing from the root layout, so it resolves against the wrong origin.
Fix it in two places. Set metadataBase once in the root layout using your production URL from an environment variable. Then set a self-referencing canonical per page from the Sanity slug:
// app/blog/[slug]/page.tsx
import type { Metadata } from "next";
import { defineQuery } from "next-sanity";
import { client } from "@/sanity/lib/client";
const POST_SEO_QUERY = defineQuery(
`*[_type == "post" && slug.current == $slug][0]{ title, "slug": slug.current, seoDescription }`
);
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>;
}): Promise<Metadata> {
const { slug } = await params;
const post = await client.fetch(POST_SEO_QUERY, { slug });
if (!post) return {};
return {
title: post.title,
description: post.seoDescription ?? undefined,
alternates: { canonical: `/blog/${post.slug}` },
};
}
The root layout needs a metadataBase such as new URL(process.env.NEXT_PUBLIC_SITE_URL), with that variable set to your real production domain. Check the variable is set in the Production environment on Vercel, not only locally.
Cause 2: preview and vercel.app URLs are crawlable
If Google can reach your deployment URL or a staging domain, it will treat it as a full duplicate of production. Look at the URL Inspection tool: if the Google-selected canonical is a different hostname, this is your problem. Block non-production environments with authentication or a noindex header rather than relying on robots.txt alone. I cover that in detail in staging site indexed by Google.
Cause 3: host and trailing slash variants all return 200
http, https, www and non-www, with and without a trailing slash: if more than one of these answers with a 200 instead of redirecting, you have duplicates by definition. Most hosts handle http to https, but the www decision is usually left open. Pick one and redirect the other permanently:
// next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
async redirects() {
return [
{
source: "/:path*",
has: [{ type: "host", value: "www.example.com" }],
destination: "https://example.com/:path*",
permanent: true,
},
];
},
};
export default nextConfig;
Next.js removes trailing slashes by default and redirects to the slash-less version, unless someone set trailingSlash to true in the config. Check that setting matches the form used in your canonicals, your sitemap and your internal links. A mismatch between them is a classic source of the "Google chose different canonical" variant.
Cause 4: the same Sanity document is reachable at several routes
This one is specific to CMS builds. A post lives at /blog/my-post, but it also resolves at /news/my-post, or /my-post, because a catch-all route queries by slug without checking the document type. Or a category change leaves old and new paths both live.
The fix is to decide one canonical route per document type, make every other route return a 404 or a permanent redirect, and make sure the GROQ filter in each route includes the type. If slugs have changed over time, the redirect handling in Sanity slug changes causing 404s applies directly.
Cause 5: query strings, pagination and filters
Listing pages with sort and filter parameters generate endless URL variants showing the same content. Canonical the filtered versions to the clean listing URL, and do not put parameterised URLs in the sitemap. For paginated lists, each page should canonical to itself, not to page one, otherwise Google may ignore the deeper pages and the posts only linked from them.
Cause 6: locale pages without self-canonicals
On multilingual sites, a translated page with no canonical, or one pointing at the default language, gets folded into the original. Each locale version needs its own self-referencing canonical plus hreflang alternates. The traffic side of this is covered in Sanity multilingual site losing traffic.
How to verify the fix
- Open the live page, view source, and confirm exactly one canonical link tag exists with an absolute production URL.
- Request the www, http and trailing-slash variants with curl -I and confirm each returns a 301 or 308 to the single preferred URL.
- Use URL Inspection on a few affected pages and compare the user-declared canonical with the Google-selected one. After a recrawl they should match.
- Confirm the sitemap only lists canonical URLs. If it lists stale or duplicate entries, see Next.js sitemap wrong on a Sanity site.
- In Search Console, open the status report and click Validate Fix. Expect the count to fall over weeks, not days.
What to ask a developer
Ask which single URL form is canonical and where that decision is enforced: redirects, metadata and sitemap. Ask whether any Sanity document type can resolve at more than one route. Ask how non-production environments are kept out of the index. If the answer to any of these is a shrug, the problem will come back after the next release.
Need this fixed
This is work I do: a canonical and indexing review is part of my Performance and Sanity audit, from $800, and fixes can roll into the same engagement.
Top comments (0)