After a store moves to a new domain, a product page opens correctly, but its canonical still points to the old address. Sometimes the developer has already replaced metadataBase, but the result has not changed. Look for the cause where that specific canonical is assembled: a base address does not fix every URL passed to it.
Below is an original educational example of a Next.js 15 store using the App Router. It has a new public domain, shop.example.ru, an old one, old-shop.example.ru, and a product page, /catalog/red-mug. The domains and product are fictional. This example can help you check the configuration, but it cannot establish the cause of an issue on your site without inspecting the code and server response.
First, record the page URL and the actual canonical
Open the problem product page through the new public domain and save the full HTML response. Find the element link with rel="canonical", and record its href, the final URL after redirects, and the HTTP status. Also check whether the response has a canonical URL in its Link header: another layer of the application may add one.
Check at least three different product pages. If they all point to the homepage, a shared parent-segment setting may be the cause. If the wrong domain appears only in one category, start with that category's layout, metadata template, or CMS data. These are areas to investigate, not a confirmed diagnosis.
A DOM snapshot is useful, but it does not replace the saved response. JavaScript, a browser extension, or a different release may change what you see. With some settings, metadata is delivered later in the response stream, so check the completed HTML rather than the first lines received.
Prepare a short list: the page URL you checked, the canonical you found, the expected canonical, the date, and the environment. For the example product page, the expected result is https://shop.example.ru/catalog/red-mug. This is appropriate only if that page is selected as the canonical one, is accessible, and contains the relevant product.
Why changing metadataBase does not help
The Next.js 15 Metadata API documentation describes two different cases: a relative URL value is resolved using metadataBase, while an absolute value uses its own address. So if alternates.canonical contains the old domain, you need to fix that value directly.
In the example store, the root layout contains this snippet:
import type { Metadata } from 'next'
export const metadata: Metadata = {
metadataBase: new URL('https://shop.example.ru'),
}This is only a metadata export: the existing layout component remains in the file. The export alone does not change routing, create a redirect, or select the correct product page for the application.
Now compare the two values in the page metadata:
// Неправильно для нашего переехавшего магазина:
const oldCanonical = 'https://old-shop.example.ru/catalog/red-mug'
// Относительный путь дополняется публичным metadataBase:
const newCanonical = '/catalog/red-mug'If the CMS returns oldCanonical, updating the layout will leave this absolute URL unchanged. If metadataBase itself contains the wrong domain, relative values will be affected. Find both settings before changing either one at random.
Also check the inheritance structure. The parent canonical for the homepage should not accidentally become the canonical for every product page. Each standalone product page should have an address that corresponds to its content.
Build the canonical from a trusted site setting
In our example, the slug has already been validated by the server when the product is loaded. The page retrieves the published product from the catalog; an unknown slug is handled separately. The following snippet shows only the generateMetadata export from the app/catalog/[slug]/page.tsx file, not a complete page implementation:
import type { Metadata } from 'next'
type Props = { params: Promise<{ slug: string }> }
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params
if (!/^[a-z0-9-]{1,80}$/.test(slug)) {
return { robots: { index: false, follow: false } }
}
return {
alternates: {
canonical: `/catalog/${encodeURIComponent(slug)}`,
},
}
}For a valid slug, the function returns a relative path; the domain comes from the layout. In a real store, use the found record's canonical slug if the incoming URL might be an alias. A regular expression check confirms only the format; the product's existence and publication status must be checked against catalog data.
Do not build a public canonical from an arbitrary Host header, query parameter, or address submitted by a visitor. The public domain is a trusted project setting. If it is stored in an environment variable, check it separately in the build and in the running process. Record the expected value for each release so that the old domain does not return on the next deployment.
Prefer a base origin without a nested path if the store is located at the domain root. A project with a base path needs its own URL-generation test: mechanically concatenating strings often leads to a duplicated prefix.
Separate production, preview, and local development
Each environment has a different purpose. Public production should return the correct URLs for primary pages. Preview is for checking upcoming changes and should not automatically expose an unpublished catalog to search. Local addresses should not appear in the public sitemap at all.
For the same public product page, preview can show the production version's canonical, but this does not replace a separate policy for restricting access to the test environment. Private previews should also be protected with access controls. If the content differs substantially, do not treat the two pages as duplicates just because their paths look similar.
Yandex treats canonical as a recommendation and describes reasons it may not be followed, including an inaccessible primary page, multiple values, and a different domain. So an accidental canonical pointing to another store should be fixed rather than left in the hope that the search engine will infer the intended result.
Check robots separately: a correct canonical with a remaining noindex does not make a page open to indexing. The cause of this combination is discussed in the article about robots inheritance in Next.js.
Check the fix in the completed release
Build and run the production version of the project in the agreed environment. Use ordinary GET requests to check the homepage, a category, two existing product pages, an unknown product, and a product page with a tracking parameter. Save the completed HTML and headers for each. After deployment, repeat the request to the public domain: a local result does not confirm the CDN configuration.
Each standalone published product page should have its own primary URL. A missing product should not pose as an existing product page with a canonical pointing to the homepage. For a URL with a marketing parameter, agree in advance on which clean address is primary; the parameter should not accidentally change the identity of the product.
Next, compare the canonical with internal links and the sitemap. If the product page template is fixed but the product list still points to the old domain, visitors and crawlers are still getting conflicting paths. In a technical audit, check the public pages; retain the exact scope of the report so you do not apply the findings for one product page to the entire catalog.
The search engine's decision should be checked separately after crawling, in webmaster tools. A successful HTML check confirms that the signal has been fixed; it does not guarantee an immediate change to the selected page or an increase in rankings.
What to send the developer and how to approve the work
Send a list of problem URLs and expected canonicals, the HTML from before the fix, details about the environment, and the location where the public domain is stored. Ask them to find the source of the absolute old address, fix how the metadata is generated, and check inheritance across different segments. Do not phrase the task as “change every canonical to the homepage.”
Acceptance criteria include a unique, correct canonical for the product pages checked, an accessible canonical target, no extra values, consistent robots directives, and clean public URLs in the sitemap. Add a check after the next release: environment-related errors often return during a rebuild.
Compare your project's architecture with the Next.js 15 overview. If you use the Pages Router, a third-party head library, or separate CMS-generated links, do not copy the Metadata API export shown here without adapting it. First find out which code actually produces the incorrect element in the final response.