URL redirect: How to create it in Magento

URL redirect

URL redirect is a common practice in the Magento website that helps enhance customer experience and maintain the brand’s authority. In some cases, permanently redirect the old URL into a new one is essential to make your site more well-structured and perform well in SEO as well as look good in shoppers’ eyes. This post will guide you on how to create URL redirect in Magento 2 via Magento backend and using functions.

1. What is a URL Redirect?

A URL redirect basically takes your URL and points it to another. For instance, you got the URL “oldsite.com” and you wanted users to instead be directed to “newsite.com”. You would utilize a redirect to effortlessly make this happen. Then whoever typed in your old URL would instantly be redirected to your new one. As you’ll see below there are a few different kinds of redirects, which you can use to satisfy your business goals.

  • 301, “Moved Permanently”
  • 302, “Found” or “Moved Temporarily”
  • 303, “See other”
  • 305, “Use proxy”
  • 300, “Multiple Choices”

URL redirect

1. 301

Magento 301 URL redirects are permanent redirects. This is one of the most commonly used and powerful methods for implementing URL redirects across your website. This 301 redirect is also advantageous for SEO purposes, as it passes over 90% of the link juice of the existing domain. The style of redirect combines instructions performed when the request hits the server, automatically moving to the other page


  • This URL redirect is better for SEO than a temporary type as it moves the inbound links from the redirected domain to the new one. Thus, it helps the Magento site maintain its search rankings and prevent search traffic decreases
  • This Magento 301 URL redirect is more preferable for shoppers and search engines. It shows that the webpage has moved permanently. The engines will move any link from the original page to the new URL.


  • Directing a page from one URL to another, the search engines need much time to explore and recognize the Magento 301 redirect and index the new page with the rankings.
  • Converting content becomes harder if a website adjusts its domain or when content moves from one domain to another. Due to spammers attacks and search engine suspicion, Magento 301 URL redirects need a great amount of time to be accurately examined.


Magento 302 URL redirects are more temporary and aren’t used very often. These links are used when you’re temporarily moving a webpage but have the intention to move it back to the old URL, like when you’re doing site maintenance or redesigning your Magento site.


  • 302 URL redirect is a good choice if an owner store deliberately doesn’t want to pass link equity from the old page to the new one.
  • This redirect would be preferable when site content needs to be moved temporarily, like in the case of site maintenance or redesign. Users need to be redirected to another domain to use the content.


  • 302 URL redirect doesn’t offer the rankings and search engine rates like a 301 type.
  • This Magento redirect may not pass any link juice, which may weaken the quality of SEO.

3. 303

This specific redirect is utilized in the circumstances when search results combine a single link. In order not to waste the visitor’s time by showing a page with a single search result, the system instantly redirects it to the destination page.

4. 305

This Magento 305 URL redirect indicates that access to the requested document can only be collected through a proxy server. It is clear from all the redirects’ descriptions that 301 and 302 must be the most generally utilized ones on the website, and it is indeed so. Therefore, we will focus further on these two stypes and how to create 301 and 302 redirects in Magento 2.

5. 300

Created for automatic (sometimes manual) browser selection of the most appropriate for the user request document. Most commonly, 300 URL redirect is automatic, so all comes down to the browser selecting a document with the needed language or encoding.

2. Create URL redirect in Magento 2 backend

  1. In your backend, move to Marketing > SEO & Search > URL Rewrites.
  2. Click Add URL Rewrite.
  3. Magento supports you to generate URL rewrite for items, categories, CMS pages, and custom URLs. Choose which type of URL you need to redirect from the dropdown list.
  4. If you choose For category or For product or For CMS page, you will have to choose a specific category or product or CMS page whose URL you want to redirect.
  5. The URL Rewrite Information fields will appear for you to enter.

URL redirect

  • Store: Choose the specific view where the rewrite applies.
  • Request Path: Enter the URL of the webpage to be rewritten (the old URL), without the domain name. For instance, if you want to rewrite the URL https://www.example.com/test/old.html, you only need to enter “test/old.html”.
  • Target Path: Enter the URL of the new page, without the domain name. For instance, if you want to rewrite the URL https://www.example.com/old.html into https://www.example.com/test/new.html, you need to enter “test/new.html”. (This will be automatically filled in if you select For category or For product or For CMS page at the previous step)
  • Redirect Type: Choose Permanent (301). Unless you really only want to rewrite a URL temporarily, you should always choose 301 redirects. It’s good for SEO.
  • Description: You can note down the purpose of the redirect.

6. When you’ve done, click Save.

3. Programmatically create 301 redirects in Magento 2

Below is the easiest way of how to create a 301 URL redirect in Magento programmatically:

namespace Magesolution\Some\Controller\Name\Space;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\RedirectFactory;
class Index extends \Magento\Framework\App\Action\Action
  private $redirectFactory;
  public function __construct(
      Context $context, 
      RedirectFactory $redirectFactory 
) {  
      $this->redirectFactory = $redirectFactory;
public function execute()
    $redirect = $this->redirectFactory->create();
    return $redirect;   

That’s it. Now besides the importance of URL redirect, you know how to generate and manage it. If you need any assistance with your configuration, contact with our Magento 2 Developers


4. Conclusion

A URL redirect is simple to do. However, you must conduct study to decide which form of redirect is ideal for your case and to avoid generating redirect loops. You’ll avoid harming your SEO and credibility this way. When using several domains, switching to a newly purchased domain, or trying to avoid 404 error pages, redirecting URLs is a wonderful way to avoid complications caused by duplicating content. However, if you are not confident to do this, experienced experts of Magesolution are already to help you. Or just choose our Magento 2 Website Development, you also can get awesome services you need for your business Contact us via the CONTACT FORM and our customer service will respond to you as soon as possible.

12459 Total Views 20 Views Today