A Step-Wise Guide for Fixing Canonical & Redirect Issues for Large-Scale Product URLs in Magento 2 – Adobe Commerce for SEO
Many Magento 2 sites, especially large-scale eCommerce platforms, face URL inconsistencies where category-based product URLs (/brands/…/product.html) and direct product URLs (/product.html) exist simultaneously. When improperly managed, this leads to:
To correct this, we need to:
Let’s now focus on the step-wise guide that is quick and easy to perform.
Ensure Canonical Tags Point to Category-Based URLs (/brands/…/product.html)
Magento is currently generating canonical tags pointing to /product.html, which is why Google is indexing the wrong versions. To fix this site-wide, update the canonical URL logic in Magento 2:
Modify the Canonical Tag Generation
Custom Code Fix (If Needed)
If Magento is still enforcing /product.html as canonical, override it using default.xml:
<referenceBlock name="head.additional">
<block class="Magento\Framework\View\Element\Template" name="custom.canonical" template="Magento_Theme::custom_canonical.phtml" />
</referenceBlock>
Then, create custom_canonical.phtml to output category-based canonicals dynamically:
<?php
$product = $block->getProduct();
$category = $block->getCurrentCategory();
if ($category) {
$canonicalUrl = $block->getUrl($category->getUrlPath()) . $product->getUrlKey() . ".html";
} else {
$canonicalUrl = $block->getUrl($product->getUrlKey() . ".html");
}
?>
<link rel="canonical" href="<?= $canonicalUrl ?>" />
This forces the canonical tag to include the category path when available.
Since Google has already indexed the shorter URLs (/product.html), we need to redirect them to the correct category-based URLs (/brands/…/product.html):
🚀 Scalable Redirect Implementation
Given the large number of products (400,000+), we must handle redirects efficiently.
Option 1: Server-Side Redirects (Preferred for Large-Scale Sites)
Apache .htaccess Redirect (Efficient for Large Sites)
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9-]+)\.html$ [NC]
RewriteCond %{DOCUMENT_ROOT}/brands/*/%1.html -f
RewriteRule ^([a-zA-Z0-9-]+)\.html$ /brands/dmf-lighting/$1.html [R=301,L]
Nginx Redirects (Even Faster)
location ~* ^/([a-zA-Z0-9-]+)\.html$ {
if (-f $document_root/brands/dmf-lighting/$1.html) {
return 301 /brands/dmf-lighting/$1.html;
}
}
Option 2: Bulk Import Redirects via Magento Admin (Slower, But Alternative)
Avoid using Magento’s database for all 400,000 redirects—it can slow down performance.
After fixing the canonical tags and implementing 301 redirects, we need to prompt Google to reprocess the URLs.
Wait 1-2 weeks and check:
Check Google Search Console:
✔ Fix Canonical Tags to point to /brands/…/product.html
✔ 301 Redirect /product.html → /brands/…/product.html via Apache/Nginx rules
✔ Submit the correct URLs in the Google Search Console
✔ Remove old URLs from indexing to speed up reprocessing
✔ Monitor search rankings to confirm Google has switched to the preferred URL structure
This structured approach ensures SEO best practices, improves rankings, and consolidates authority without overloading Magento’s database.
This step-wise guide is a useful reference for URL optimizations. However, for a more structured approach towards on-page SEO, a detailed analysis and audit by experts is needed. Enter Krish, an expert-led Digital Marketing agency specializing in Magento – Adobe Commerce, for all things organic and beyond. Connect with us today!
As Director - Marketing, Zenul leads the marketing and branding at Krish. He brings with him an in-depth understanding of the evolving digital ecosystem and has a proven expertise and experience in strategic planning, market and competition analysis, creating and implementing client-centered, lead-gen and brand marketing campaigns. He has a heart for technology innovation and has been a keynote speaker on various platforms.
3 July, 2025 The distinction between flourishing digital commerce enterprises and those merely surviving often hinges on a fundamental practice: maintaining comprehensive visibility into operational performance. While competitors chase flashy marketing campaigns and trending features, astute retailers systematically conduct thorough assessments that uncover hidden opportunities and identify silent profit-killers within their digital storefronts. Consider this reality: When did someone last thoroughly examine whether your checkout process inadvertently drives customers away? Or verify if that supposedly lightning-fast site speed actually feels sluggish to mobile users? Or assess whether outdated plugins create security vulnerabilities that could devastate customer trust overnight? Most digital commerce operators rely on assumptions rather than concrete insights. They assume adequate performance because sales remain stable, assume security sufficiency absent any breaches, and assume a satisfactory user experience without excessive complaints. However, assumptions don't build million-dollar enterprises. Data does. This is precisely what comprehensive digital commerce audits provide: objective, actionable intelligence about what functions effectively, what requires attention, and what actively costs revenue.
Never miss any post, stay tuned!