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.
26 August, 2025 Most retail stores today feel like a time warp. Customers wait in lines, employees track inventory by hand, and pricing changes weekly if we’re lucky. Meanwhile, customer expectations have gone into orbit! They want Amazon-level personalization and convenience everywhere they shop. The gap between retail reality and customer expectations keeps widening. McKinsey research shows AI could unlock up to $390 billion in value for retail, while the global AI in retail market is projected to grow from $7.14 billion in 2023 to $85.07 billion by 2032. More interesting from a Salesforce article: 39% of shoppers and 54% of Gen Z are already using AI for product discovery. Smart retailers aren't waiting. They're building systems that think, learn, and adapt faster than human teams ever could. The ones getting this right aren't just adding AI features. They're creating entirely new ways to operate.
Never miss any post, stay tuned!