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.
11 July, 2025 The landscape of online shopping is undergoing a profound transformation. Gone are the days when people painstakingly typed "red leather handbag with gold buckles" into a search bar. Now, a quick snap of a striking bag seen on the street can instantly bring up similar options. This isn't just about newfound convenience. It's a fundamental shift in how customers discover and acquire products. Visual search technology, once a novelty, has firmly established itself as a business imperative. It allows shoppers to use images instead of text, effectively bridging the gap between what catches their eye and what they can find. For retailers, this isn't merely about incorporating a cool new gadget; it's about connecting with customers precisely where they are in their shopping journey.
Never miss any post, stay tuned!