How to fix seo variant urls in sitemap on Next.js (Headless)
Remove product variant URLs (e.g. ?variant= or ?sku= query strings) from your XML sitemap and keep only the canonical base product URL for each product.
Steps for Next.js (Headless)
- Locate your sitemap source — either `app/sitemap.ts` (App Router) or a custom `pages/sitemap.xml.tsx` / `getServerSideProps` route (Pages Router). This is the ONLY place to make changes.
- In the function that builds sitemap entries, strip every query string (e.g. `?variant=`, `?sku=`, `?color=`) from product URLs before they are emitted. Use `new URL(rawUrl)` and read only `origin + pathname` — discarding `search` entirely.
- Deduplicate the resulting URL list with a `Set` or `Map` keyed on the clean pathname, so that multiple variants that share the same base product URL collapse into a single sitemap entry.
- Return (or render) only the deduplicated, query-string-free canonical URLs. For App Router this means returning the cleaned array from `sitemap.ts`; for Pages Router this means building the XML string from the cleaned array inside `getServerSideProps`.
- Verify the output by visiting `/sitemap.xml` locally and confirming no `?variant=` / `?sku=` parameters appear, and that each product path appears exactly once.
- Optionally set a `<link rel='canonical'>` on every product page (via `generateMetadata` or `next/head`) pointing to the same base URL, so crawlers that reach a variant URL are explicitly directed to the canonical version.
What is seo variant urls in sitemap?
When shoppers (or your platform) switch between product options like size, color, or material, the URL often changes to include a query string such as `?variant=12345` or `?sku=red-large`. These variant URLs all show the same product page with slightly different state — they are not separate products. An XML sitemap is a file that tells search engines which pages you want indexed. Including variant URLs in that sitemap tells Google there are many distinct pages worth crawling and indexing, when in reality there is only one canonical product page. The fix is to ensure your sitemap lists only the clean, base product URL (e.g. `/products/blue-sneaker`) for each product, with no query-string parameters attached.
Google treats variant URLs as duplicate or near-duplicate pages of the same product. Submitting them in your sitemap wastes your crawl budget — the portion of time and resources Google allocates to your site — on pages that add no indexing value, which means your real category and product pages may be crawled and refreshed less frequently. Duplicate content signals can also dilute the ranking strength of your canonical product page, splitting authority across many near-identical URLs instead of concentrating it on the one page you actually want to rank. Practically speaking, if Google indexes a variant URL instead of your base product URL, you may appear in search results with an ugly, parameter-laden link that confuses shoppers and reduces click-through rate. Keeping a clean sitemap is one of the fastest, lowest-risk wins for improving crawl efficiency and protecting your organic search traffic.
See the complete Seo variant urls in sitemap guide for every platform and the full background.
Not sure if your Next.js (Headless) store has this?
Run a free SEOLZ scan — we’ll find seo variant urls in sitemap and every other issue across your whole site.
Scan my site free