magento migration - url rewrite

Rewrite URL when migrating an eCommerce website to Magento

I recently worked on an interesting project for migrating from an old ASP.NET eCommerce site to the latest version of Magento 2 open source (2.1.9).

A common request is, they want to redirect permanently their old product URL to a new one to the new URL under Magento 2 URL structure.

I suppose that they need to redirect product with old URL:

/productdetail.aspx?ID=99 to /this-is-a-migrated-magento-product-url.html

You may think that it is just simply adding custom URL redirection in Magento URL Rewrite management like the picture below

custom URL redirection in Magento URL

But doing so would bring this URL https://yourdomain.com/productdetail.aspx?ID=99 to a 404 page.

I did a simple trick with .htaccess

RewriteCond %{REQUEST_URI}  ^/productdetail\.aspx$
RewriteCond %{QUERY_STRING} ^ID=([0-9]*)$
RewriteRule ^(.*)$ https://yourdomain.com/productdetail/id/%1 [R=301,L]

and then, I will add this custom url to magento backend

custom url to magento backend

After that, when visiting

https://yourdomain.com/productdetail.aspx?ID=99

It will be redirected to

https://yourdomain.com/this-is-a-migrated-magento-product-url.html

I really hope my quick tip will save you guys time for finding a solution to saving the website SEO ranking after migration and avoiding users with annoying 404 errors.