After migrating from Magento 1 to Magento 2, the shop lost 60% of organic traffic within 2 weeks. Ahrefs showed 4000 404 errors. Old product and category URLs were not being redirected. Fix time: 3 days.
Symptoms
- Drastic drop in organic traffic after migration
- Google Search Console: thousands of 404 errors
- Old Magento 1 URLs (e.g.
/catalog/product/view/id/123) return 404 - External links and customer bookmarks stopped working
Diagnosis
# Export all URLs from old M1 database SELECT request_path, target_path, options FROM core_url_rewrite WHERE store_id = 1 INTO OUTFILE '/tmp/m1_urls.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY ' ';
Solution
<?php
// Import M1 redirects into M2
$m1Urls = array_map('str_getcsv', file('/tmp/m1_urls.csv'));
foreach ($m1Urls as $row) {
[$requestPath, $targetPath] = $row;
$existing = $rewriteCollection
->addFieldToFilter('request_path', $requestPath)
->getFirstItem();
if ($existing->getId()) continue;
$rewrite = $rewriteFactory->create();
$rewrite->setStoreId(1)
->setIdPath('custom_' . md5($requestPath))
->setRequestPath($requestPath)
->setTargetPath($targetPath)
->setRedirectType(301)
->setIsSystem(0);
$rewriteResource->save($rewrite);
}
# Alternative - nginx redirects (faster for large sets)
map $request_uri $new_uri {
/old-product.html /new-product.html;
/old-category/ /new-category/;
}
if ($new_uri) { return 301 $new_uri; }
Takeaways
The SEO migration plan must be part of the migration project – not an afterthought. Before launching M2: export all M1 URLs, generate a redirect map, test every redirect. Monitoring Google Search Console for the first 4 weeks after migration is mandatory.
