URL rewrite is a great function in Magento 2 allowing users to edit any URL of category, product, or CMS page. URL rewrite will rewrite existing “ugly” URLs that are not easy to remember and makes them more search- engine friendly as any links that point to the previous URL are redirected to new address once the rewrite goes into effect. Consequently, the visitors who access the old not-nice link will be redirected to the new URL.
Here is an example of URL rewrite:
URL without Rewrite
URL with Web Server Rewrite
As can be seen, we need to install and enable Apache Rewrites first. After you configured rewrite, the ugly URL with “index.php” will be redirect to the nicer one. Simultaneously, the bad URL that brings no added value to SEO or customers’ experience will be auto-ignored and redirected as well. Therefore, from Magento 2 back-end, configuring the URL rewrite make the currently updated link(s) more friendly with search engines and easier for the readers.
Configure URL rewrite
In this post, we will learn how to set up URL rewrites and set up automatic redirects from that.
- Log-in to the back end of Magento 2.
- In Admin side bar, go to Stores > Configuration >Web.
- Explore Search Engine Optimization section.
- Set Yes to the Use Web Server Rewrites.
- Click Save Config. to save all the process.
Magento 2 allows your store to be configured to automatically generate a permanent redirect as the URL key of a product changes. The section of Search Engine Optimization for the product record, check the checkbox under the URL key to see whether it indicates enabled permanent redirects for your catalog. If the online store is already configured to auto-redirect catalog URL, updating URL key and making a redirection is simple.
2. Automatic redirects set up
Login to the back end of Magento 2.
On the Admin sidebar, choose Stores > Configuration > Catalog > Catalog.
Go to Search Engine Optimization section.
Select Yes for the section of Create Permanent Redirect for URLs if URL Key Changed.
Click Save Config. to save the process.
To automatically redirect Catalog URLs, we follow these steps:
- On the Admin side bar, choose Products > Catalog.
- Find the product(s) in the list and click to open the record(s). On the left side panel, choose Search Engine Optimization.
In this section:
- Ensure the Create Permanent Redirect for old URL checkbox is selected. Otherwise, repeat all steps in the instructions for automatic redirects enable.
- If it is necessary, update the URL Key. It worth noticing that all characters should be lowercase and hyphens are used instead of spaces.
- Click Save to save all the changes.
Now you can follow the links in the messages appearing at the top of your workspace to refresh the cache and index. The permanent redirect is in effect for the product(s) and any associated category URL.
In order to check the redirect records, go to Admin sidebar, choose Marketing > SEO& Search > URL rewrites. The recent updated permanent redirects appear at the top of the list.
It comes to the end of URL Rewrite Configuration in Magento 2.