Magento 2 URL Rewrites Full Tutorial You Should Not Miss

Magento 2 URL Rewrites Full Tutorial You Should Not Miss

Sometimes, you may wonder if a friendly URL is really important to your website?  The answer is: absolutely!

When it comes to your website, your URLs are often the first thing Google and customers will see. A friendly URL that is easy to read and includes words describing the content of the webpage can help visitors remember your website address and improve your website’s searching rank.


SECURE YOUR SEO JUICE: Using Magento 2 SEO Plugin to quickly audit and update your URLs as well as others SEO components.

For example, a company may use the URL “www.[company].com/service/” for the support section of their website, this is much easier to remember than a long convoluted URL like “www.[company].com/section/service/default.aspx?id=123&lan=en”.

In order to help every Magento 2 website have better URLs, we want to introduce a technique called Magento 2 URL rewrites that can turn unsightly URLs into friendly ones. Let’s see the detailed guide below to understand more!

What Are Magento 2 URL Rewrite?

Magento URL Rewrite is a useful tool that allows you to change any URL associated with a product, category, or CMS page. After enabling the Rewrite, any links that point to the previous URL are redirected to the new address.

It’s can be said that the Magento URL rewrite is one of the best and quickest ways to improve user experience and search friendliness of websites.

Benefits of Magento 2 URL Rewrites

Set aside the fact that URL rewrites are essential to SEO maintenance practices, their influence is far bigger and wider than that.


Let’s break down this mini-infographic.

Structural Benefits

Magento does auto-generate URL for your products but they’re a bit of a struggle to work with. Here is where the URL rewrites Magento 2 shine – elevated user experience with undoubted sales potential.

A system of organized URL will allow customers to follow and explore your products at ease. But outside of your product page, Google and the search engine will actually reward your store due to the friendliness that is your site structure. After that, you can smartly put your wanted page on the SERP with the keyword you want to rank for. 


And because of that, your page’s purpose comes through and results in a lower bounce rate with a bigger conversion number.


I’m pretty sure that you’ve read about the power of internal linking. On the off chance that you haven’t, here is it. 

The most pronounced example is Amazon – the biggest e-commerce site on the Net. Every product has a set of related products, customer-also-brought suggestions, and tons of other internal links.


What they do is improving your conversion rate and boost your authority behind the scene. There are multiple birds you’ll hit with a great Magento 2 URL rewrites initiative. And let’s learn about them right now.

Magento 2 URL Rewrites Configurations

Enable Magento 2 URL Rewrites

  • Log in to the Admin panel.
  • Click Stores→Configuration→General→Web. 
  • Expand Search Engine Optimization
  • Set Yes for Use Web Server Rewrites field.
  • Click the Save Config button.
  • Flush Cache.

Set Up Automatic URL Redirects

After enabling URL Rewrites Magento 2, you have to configure automatic URL Redirects that allow your Magento 2 store to automatically generate a permanent redirect whenever the URL key of any product is changed. Let’s follow the below steps:

  • Go to Stores→Configuration→Catalog→Catalog.
  • Expand Search Engine Optimization.
  • Set Create Permanent Redirect for URLs if URL Key Changed to Yes.
  • Click the Save Config button.
  • Flush Cache.

Change Product Page URLs

For products, please follow these steps:

  • You go to Catalog→Products, choose needed products.
  • Expand the drop-down Search Engine Optimization.
  • Update the URL Key.
  • Save the changes.

Change Category Page URLs

For Categories, please follow the below steps:

  • Go to Catalog→Categories, choose needed categories.
  • Expand the drop-down Search Engine Optimization.
  • Update the Magento URL Key.
  • Save the changes.

Change CMS Page URLs

For CMS page, please follow the below steps:

  • Go to Content→Pages, click Edit the page you need.
  • Expand the drop-down Search Engine Optimization.
  • Update the Magento URL Key.
  • Save the changes.

Note: Well-optimized URLs are important for both search engine optimization and user experience. To have a friendly URL, please keep in mind that the URL should be short, include keywords, describe the content, use hyphens to separate words, and use lowercase letters.

Add Magento 2 URL Rewrites And Create A Redirect Rule

There is another way to change URLs for products, categories, and CMS pages. Let’s see the steps below: 

  • Go to Marketing→SEO&Search→URL Rewrites, a grid of redirect records will appear. 
  • Click on the Add URL Rewrite button to create new Magento 2 URL rewrites or click Edit to edit existing URL rewrites.

url rewrites magento 2-add new

  • Configure the following settings:

Create URL Rewrite: Choose the option you need to create a Magento URL rewrite (Custom, For category, For product, For CMS page).

Store: Select the store view.

Request Path: Input a new Magento URL key and suffix (the Request Path is the original path).

Target Path: Enter the targetted path (the Target Path is the new path corresponding to the new web address).

Redirect Type: Choose either Temporary (302) or Permanent (301) redirect type.

– A 301 redirect sends the message to search engines that a website or page has been moved permanently.

– A 302 redirect lets search engines know that a website or page has been moved temporarily.

Description: Describe the rewrite.

  • Click Save button.

A Solution To Fasten The URLs Rewrites Process

In case you have hundreds or thousands of products that need rewriting, it will waste a lot of time handling them one by one. Rather than that, you can’t export your URLs for further and easier at management and update.

In order to save time, you can use Magento 2 Import Export URL Rewrites extension to import Magento URL Rewrites via a CSV file. Therefore, all URL Rewrites in Magento 2 can be quickly updated at the same time and your process will be shortened in just a few minutes.

m2-import-export-url-rewrites (1)

GRAB NOW: Using the Magento 2 Import Export URL Rewrites extension to craft your new URL structure at ease.

Make URL Rewrites Magento 2 Programmatically

Enabling the 301 is a useful tool to redirect any links to the previous URL to the new address. Let’s follow the steps below to accomplish this:

  • Generate a constructor file:
* @var \Magento\UrlRewrite\Model\UrlRewriteFactory
protected $_urlRewriteFactory;
* @param Context $context
* @param \Magento\UrlRewrite\Model\UrlRewriteFactory $urlRewriteFactory
public function __construct(
    Context $context,
    \Magento\UrlRewrite\Model\UrlRewriteFactory $urlRewriteFactory
) {
    $this->_urlRewriteFactory = $urlRewriteFactory;
  • Create the custom Magento 2 URL rewrite in execute method:
$urlRewriteModel = $this->_urlRewriteFactory->create()
/* set current store id */
/* this url is not created by system so set as 0 */
/* unique identifier - set random unique value to id path */
$urlRewriteModel->setIdPath(rand(1, 100000));
/* set actual url path to target path field */
/* set requested path which you want to create */
/* set current store id */

Congratulations! You have successfully configured URL redirects in your Magento 2 store.

Sum It Up

Let’s say goodbye with bad URLs and welcome friendly ones. I hope that this topic of Magento URL Rewrite will give you lots of useful information and suggestions for your SEO strategy.

And if you’re looking for a gourmet version with a professional touch on URL rewrites in Magento 2, don’t hesitate to CONTACT BSS – we’re here to help you strengthen your e-business with the best solution available!

Write A Comment