How to work with URL Rewrite functionality in Magento 2

Every once in a while, an online store might go through changes, and Magento-based are no exception. For example, there might be changes in pages for items or indexes. Alternatively, a store may undergo a major rebuild! At that point, assuming the URLs of the pages are not dealt with, then the store may lose some clients because they will arrive on pages that don’t exist any longer.

Additionally, the administrator would need to revamp the URL with watchwords with higher SEO worthiness to make it more beneficial for the SEO of the store.

Magento 2 URL Rewrite is a feature that allows store owners to re-customize the specific URL in case the store undergoes changes. URL rewrites make it possible to make existing URLs more “search engine friendly” and easier for users to read. A good URL directly efforts in SERP.

The URL Rewrite tools

The URL Rewrite tool lets you change any URL is associated with a product, category, or CMS page. When the rewrite goes into effect, all links pointing to the previous URL are redirected to the new address.

Single URL rewrite

The URL Rewrite tool can be used to create product and category rewrites, as well as custom rewrites for any page in your store. When the rewrite goes into effect, any existing links pointing to the previous URL are seamlessly redirected to the new address.

URL rewrites can be used to add high-value keywords to improve the way search engines index the product. You can also use rewrites to create additional URLs for a temporary seasonal change or permanent change. Rewrites can be created for any valid path, including CMS content pages. Internally, the system always references products and categories by their ID. No matter how often the URL changes, the ID remains the same. Here are some ways you can use URL rewrites:

  • System URL

  • Original URL

  • Redirected Product URL

Magento2 offers these URL rewrite types:

  • Product Rewrites
  • Category Rewrites
  • CMS Page Rewrites
  • Custom Rewrites

Multiple URL Rewrites

You can quickly update URL rewrites for multiple or all products at once by following steps. Update multiple URL rewrites:

  • On the Admin sidebar, go to Catalog > Products.
  • Select all of the products for which you want to update URL rewrites.
  • Under Actions, choose Update attributes to update multiple or all rewrites.
  • Under PRODUCTS INFORMATION, click the Websites tab.
  • In the Add Product To Websites section, select all websites for which you want to restore URL rewrites.
  • When ready to update, click Save.
  • All selected products will be re-added to the selected websites, and URL rewrites will be regenerated.

Words for redirection and rewriting are frequently utilized conversely, however they allude to marginally various things. The rewrite word means changes in the manner the URL is shown up for the visitor. The redirection is used when the URL on the server needs to be refreshed, and it can be either impermanent or last forever.

URL redirections can be utilized along with the rewrites to simplify altering the URL key of an item, class, or page and save existing URL connections.

Any store that uses Adobe’s eCommerce framework can be arranged to consequently create a long-lasting redirection. It can be done at whatever point the URL key of an item or classification changes.

A store manager can configure redirection in the Search Engine Optimization segment by clicking the checkbox underneath the URL key. This option shows if long-lasting redirections are empowered.

Assuming the store is already designed to consequently divert a list URLs to other addresses, making a redirection is just as simple as refreshing the URL key. The interaction to make a programmed redirection is something similar to the items and classifications.

At the point when programmed redirects are empowered simultaneously, the item class setup is saved, all rewrites for item and classification are produced with no delay and typically are put away in data set tables. This could bring huge execution issues for item classes that consist of many items.

Such a performance problem can be solved by changing a default setup and avoiding rewrites of the URLs for classes and items when the classification setup is saved. For this situation, rewrites for item URLs are created while including only standard item URL.

Configuring automated redirections

  • On the Admin sidebar, go to Stores > Settings > Configuration.
  • In the left panel, expand Catalog and choose Catalog underneath.
  • Expand Expansion selector the Search Engine Optimization section.
  • Set Create Permanent Redirect for URLs if URL Key Changed to Yes.
  • When complete, click Save Config.

Automatically Redirect Product URLs

  • On the Admin sidebar, go to Catalog > Products.
  • Find the product in the list and click to open the record.
  • Expand Expansion selector the Search Engine Optimization section and for the URL Key field, do the following: Make sure that the Create Permanent Redirect for old URL checkbox is selected. Update the URL Key as needed, using all lowercase characters and hyphens instead of spaces.
  • When complete, click Save.
  • When prompted to refresh the cache, follow the links in the message at the top of the workspace. The permanent redirect is now in effect for the product and any associated category URLs.

Skip Generation of Product URL Rewrites for Category Save

Turning off automatic generation of category/products URL rewrites results in permanent removal of all existing category/product type URL rewrites, which cannot be restored. This can potentially cause unresolved category/product type URL conflicts that will require a manual update of the URL key to resolve.

  • On the Admin sidebar, go to Stores > Settings > Configuration.
  • In the left panel, expand Catalog and choose Catalog underneath.
  • Expand Expansion selector the Search Engine Optimization section.
  • For the Generate “category/product” URL Rewrites field, clear the Use system value checkbox and set the value to No.
  • In the confirmation dialog, click OK to confirm the change and the removal of existing URL rewrites.
  • When complete, click Save Config.

Note: When automatic redirects are enabled and you save a category, all product and category rewrites are generated in real-time and stored in rewrite tables by default. This could result in significant performance issues for categories with many assigned products.

The solution is to change this default and skip the generation of category/products URL rewrites of products for category save. In this case, product rewrites are generated only for the canonical product URL. See Automatic Product Redirects for more information. In the process of redirection, all GET parameters specified in the URL will be removed due to security reasons.

Configuring URL Rewrites

URL rewrites make it possible to make existing URLs more search engine friendly and also easier for humans to read. Enabling Web Server Apache Rewrites is part of the initial Commerce setup.

Commerce routinely uses URL rewrites to remove the file name index.php that normally appears in the URL just after the root folder. When Web Server Rewrites are enabled, the system rewrites each URL to omit index.php. The rewrite removes words that convey nothing of value to search engines or customers and has no impact on performance or site rank.

URL without Web Server Rewrite

URL with Web Server Rewrite

How to configure URL rewrites

  • On the Admin sidebar, go to Stores > Settings > Configuration.
  • In the left panel where General is expanded, choose Web.
  • Expand Expansion selector the Search Engine Optimization section.
  • Set Use Web Server Rewrites to your preference.
  • When complete, click Save Config.

Canonical URLs

For SEO purposes, it is a good idea that each of your web pages has only one distinct URL.

If you have a single page accessible by multiple URLs, or different pages with similar content, Google sees these as duplicate versions of the same page. Therefore, Google will choose one URL as the canonical version and crawl that, and all other URLs will be considered duplicate URLs and are crawled less often.

If you don’t explicitly tell Google which URL is canonical, it will make a choice for you or consider them both of equal weight. This could lead to unwanted behavior, run the risk of an ineffective crawl budget and low distributed backlinks.

Depending on how you set up your site, there may be several versions of your site in the Google index, including:

Automatic Redirects can be created with the Advanced Seo Suite Ultimate extension for Magento 2. Mirasvit SEO Suite Ultimate brings all the necessary tools to quickly and easily manage redirects to any URLs.

Redirects are vital for SEO. If you change your URL structure, you have to tell the search engines to go to the new page URLs in order to preserve the search rankings you have already achieved.

Redirects are important for your customers. Learn how SEO optimization brings benefits in our article.