URL Rewrite is one of the most useful tools that come out of the box with Magento 2. It allows you to create multiple temporal server URL redirects for any product, category or CMS page directly from the admin panel, which is great for seasonal sales or promotions or permanent if you simply want to overwrite a URL. To start using this tool you must first enable it and then just create as many as you want as explained in the steps below.
Steps to enable URL Rewrite tool:
To enable URL rewrites
- Go to Stores > Settings > Configuration > General > Web in the left toolbar menu.
- Expand the Search Engine Optimization section.
- Set Use Web Server Rewrites to “Yes”.
- When complete, click the Save Config button.
Steps to create new URL Rewrite rules:
Log into your Magento 2 Store Admin panel.
Click on “Marketing” option on the left toolbar.
Click on “URL Rewrites” option under “SEO & Search”
Click on “Add URL Rewrite” button located on the top right corner.
Select “Custom” from the “Create URL Rewrite” drop-down menu.
Select “Default Store View” from the “Store” drop-down menu.
Enter the current URL (the URL you want to overwrite) in the “Request Path” text field.
Enter the target URL (the new destination URL) in the “Target Path” text field.
Select the redirect type as “Temporary (302)” if you want to do it only for some time or “Permanent (301)” if it is a permanent redirect from the “Redirect Type” drop-down menu.
Click the “Save” button at the top right corner to finally save the new URL Rewrite.
The URL Rewrite tool in Magento 2 is really flexible and allows you create as many Temporary (302) or Permanent (301) redirects as you want with ease. Thank you all for reading the post and if it was useful don’t forget to share it with your colleagues.
See you again in the next article.