Hello Magento Friends,

In this Magento 2 blog illustration, I will explain How to Add URL Rewrite for Product Programmatically using Root Script in Magento 2. 

URL rewrite involves modifying the URL of website pages to create more user-friendly URLs. In Magento 2, you can Add URL Rewrite from Admin or Add URL Rewrite Programmatically.

By default, Magento generates the URL key for a product based on its name or specified attribute values. However, you can modify or override the URL key to create a custom URL for a product using the URL rewrite functionality.

Product URL rewrite allows you to customize the URL of the product page of your Magento 2 store. It enables you to create SEO-friendly URLs, manage URL redirects, and improve the overall user experience by providing more descriptive and memorable URLs for your products. They play a crucial role in SEO optimization and ensuring that customers can access product pages through clean and meaningful URLs.

Steps to Add URL Rewrite for Product Programmatically using Root Script in Magento 2:

Step 1: Create Producturl.php in your Magento root directory and add the following code.

Product URL will be generated if not available in the current URL rewrite table.

Product URL Rewrite


This way, you can add product URL rewrite programmatically using root script in Magento 2. If you face any issues, share them with me through the comment box without any hesitation. I will be quick to provide you with the solution. Moreover, share the tutorial with your friends to help them add product URL rewrites in their Magento 2 stores. 

Happy Coding!

Click to rate this post!
[Total: 1 Average: 5]