October 7,2021

Magento 2 Guide: Setting Up URL Rewrites

byAvatar Tim

Here, we will be looking at how to set up both manual and automatic URL rewrites in Magento 2, but before we do that, we need to understand:

What’s a URL rewrite

A rewrite is where a page URL key is changed to a new page key, with a reference set up, so that anyone using the old URL page key is sent to the new one. These are used so that search engines/people end up on the page they’re looking, so they don’t end up on a ‘404/missing page’.

Let’s look at an example:

One of the products on your website is a greeting card. Due to a human error, there was a mistake when it was set up, so now you have a misspelling on the product URL –

www.example.com/gretings-card

You go in to change to URL, to correct this mistake so now your product URL is –

www.example.com/greetings-card

However, one of your blogs the points to the products old (misspelt) URL, which doesn’t get changed, now if anyone clicks on the link to the product, they’ll end up on a ‘404 page’, leading them to believe the product no longer exists.

A URL rewrite fixes this issue so that wherever there is a link to the old URL, there is a reference in your website for that to take them to the new updated URL.

page-redirect-explanation

Need help with Magento?

We are experts in Magento, with experienced designers, developers & marketers. If you need a hand, get in touch.

Why they’re important

These are needed for both user experience and search engines.

For a user the result would be that they follow a link that leads them to a ‘404 does not exist page’, this would not be a great user experience and could result in a lost sale. Having a redirect in place lets users get to the page they wanted to visit.

For search engines, they will follow this link and find that the page does not exist, it will believe the page has been removed from the website, any authority this may have will be lost, and if the page got traffic, the search engines will remove this from the search results as it’s not good for users to land on a page that does not exist. A 301 redirect lets them know that the page has been moved to a different URL key and that it still exists on the website.

In Magento, this all can be taken care of by the CMS itself. Magento allows for these rewrites to be implemented both automatically and manually. Automatic URL rewrites will be put in place by the system whenever you change a category, product and CMS page URL key.

Manual are redirects are ones that you set up yourself.

Turning on automatic URL rewrites in Magento

Overview

  1. Log into your Magento admin area
  2. Head to Store > Configuration > Catalog > Catalog s
  3. Expand the Search Engine Optimisation tab.
  4. Change Create Permanent Redirect for URLs if URL Key Changed to yes.
  5. Hit the save button and you’re finished.

Log into your Magento backend and head to Store > Configuration.

stores configuration menu magento2 backend

In the configuration menu, you’ll need to expand the Catalog section, then go to the Catalog sub-menu item.

magento-2-store-configuration-catalog-catalog

Now you’ll need to look down the page and expand the Search Engine Optimisation. In here there will be an option called Create Permanent Redirect for URLs if URL Key Changed, make sure this is set to yes.

magento-2-create-permanent-redirects-automatically

Hit the save button and you’re done, you may also need to flush the cache for this to take effect). This will now ensure going forward that a URL key for a product, category or CMS page, the old URL key will point to the new one.

Need help with Magento?

We are experts in Magento, with experienced designers, developers & marketers. If you need a hand, get in touch.

Setting up a manual URL rewrite in Magento

Overview

  1. Log into your Magento admin area
  2. In the left menu head to Marketing > URL Rewrites
  3. Click the Add URL Rewrite button
  4. In Request Path, put the URL key you want to be changed
  5. In Target Path put the final page URL key
  6. Choose your redirect Type – 301 (permanent) or 302 (temporary)
  7. Add a description of why this is being set up
  8. Save and test it works correctly

What are 301 and 302 redirects?

You may have seen in the overview of adding a manual redirect in Magento, that there was an option of choosing either a 301 (permanent) or 302 (temporary) redirect. If you’re not sure what the difference is and which one you should use, don’t worry, we’ll briefly explain.

301 (permanent) redirect – this is used where you want to change a page’s URL key to a new URL key permanently. If you have a product page (like above), where there is a spelling error in the URL key, which you want to correct. In this case, you’d want this to be a permanent change.

302 (temporary) redirect – this is used where you want to point a page’s URL key to another page, but only temporarily, where the page URL key will be changed back in future. This could be used where you have a page for events which needs to be updated. You set up a temporary page, explaining that the events page is being updated and for all the information about upcoming events to visit your Facebook page. In this case, you’d set up a 302 redirect from the events page, to the temporary page. This then lets search engines know that, though this page is temporarily unavailable and will be back soon.

Now, on how to implement a URL rewrite in Magento 2.

Log into your Magento admin area and from the left menu, head to Marketing > URL Rewrites.

magento-2-marketing-url-rewrites

You’ll be taken to a page which has all the URL rewrites that have been created. Click the Add URL Rewrite button.

magento-2-add-url-rewrite-button

Make sure the Create URL rewrite drop down at the top is on Custom, select the store you want the rewrite applied to. In the Request Path, put the URL key you want pointing to a new page. In Target Path, put the final URL key where you want people to end up.

For Redirect Type, select either 301 (permanent) or 302 (temporary).

Add a brief description as to why this is being set up and hit save to finish.

magento-2-adding-manual-url-rewrite

Head to the front end of the website to test that the request path URL key takes you to the target path URL key.

Now you’ve know what URL rewrites in Magneto are and how to set them up.

We are a experienced Magento Agency, working with brands both large and small. If you need any help with your Magento Store, get in touch with us today!

Continue Reading

What sets our website designs apart?

Website design goes beyond aesthetics; it's about crafting an experience that keeps your audience engaged and encourages them to return to your business.

Avatar
Leanne October 18th, 2024
Understanding Website Architecture: A Comprehensive Guide

Did you know that, on average, users spend only 54 seconds on a website? In that brief moment, it’s crucial to grab their attention, engage them, and make them want to stay on your website. So, if your site is difficult to navigate, visitors are more likely to leave and seek an easier experience elsewhere. … Continued

Isev Team
Isev Team October 7th, 2024
How to Get a High Quality Website

One of our favourite quotes is “If it’s done right, it’ll last forever”, a statement that is specifically true for how important a quality website company, with talented developers and designers is. Sure, you could get a website built for you, or even build one yourself both at a lower cost than professional website builders … Continued

Isev Team
Isev Team September 24th, 2024
The Customer Journey: Tips and best practices

This article looks in detail at both the customer journey and the conversion funnel, analysing how they function and how they work hand in hand.

Avatar
Leanne August 15th, 2024