Magento 2 URL Rewrites

Magento 2 URL Rewrites Full Tutorial You Should Not Miss

by admin

If you are wondering if you need to do Magento 2 URL rewrites, then we have the answer for you: Yes, absolutely yes!

Magento 2 URL rewrites is a technique that can turn unsightly URLs into friendly ones. And you should know how important a friendly URL is to your website.

Sometimes, you may wonder if a friendly URL is essential 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 search ranking.

url-friendly-is-a-must

>>> 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“.

To help every Magento 2 website have better URLs, we decided to write this article to show you how to use the Magento 2 URL Rewrite feature. 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 URL rewrite, any links that point to the previous URL are redirected to the new address.

It’s no doubt 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.

why-magento-2-url-rewrites-important

Let’s break down this mini-infographic.

Structural Benefits

Magento does auto-generate URLs 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 URLs 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. 

work-smart-not-hard

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

Linkability

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.

internal-linking

What they do is improve your conversion rate and boost your authority behind the scenes. 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.

enable-magento-2-url-rewrites

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 the Create Permanent Redirect for URLs if URL Key Changed to Yes.
  • Click the Save Config button.
  • Flush Cache.

set-up-automatic-url-redirects

Change Product Page URLs

For products, please follow these steps:

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

change-product-page-urls

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-category-page-urls

Change CMS Page URLs

For the 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.
magento-url-rewrite-cms-page

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, and 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 the Save button.

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;
    parent::__construct(
        $context
    );
}
  • Create the custom Magento 2 URL rewrite in the execute method:
$urlRewriteModel = $this->_urlRewriteFactory->create()
/* set current store id */
$urlRewriteModel->setStoreId(1);
/* this url is not created by system so set as 0 */
$urlRewriteModel->setIsSystem(0);
/* unique identifier - set random unique value to id path */
$urlRewriteModel->setIdPath(rand(1, 100000));
/* set actual url path to target path field */
$urlRewriteModel->setTargetPath("www.example.com/customModule/customController/customAction");
/* set requested path which you want to create */
$urlRewriteModel->setRequestPath("www.example.com/xyz");
/* set current store id */
$urlRewriteModel->save();

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

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 management and update.

In order to save time, we strongly recommend you to use the Magento 2 Import Export URL Rewrites extension by BSS.

This module supports importing 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.

Check out the extension’s full list of features:

  • Quickly import URL rewrites via a CSV file
  • Offer the sample CSV file to help administrators conveniently finish data and reduce errors.
  • Validate the CSV file before importing and show messages about import results
  • Easily export available URL rewrites into a CSV file format also
  • Support importing and exporting 301 and 302 redirect types

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

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

Sum It Up

Let’s say goodbye to bad URLs and welcome friendly ones. I hope that this topic of Magento 2 URL Rewrites 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!

BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bringing high-quality products and services to optimize your business effectively. Furthermore, we offer FREE Installation – FREE 1-year Support and FREE Lifetime Update for every Magento extension.

 

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.