Redirection is the process of forwarding a URL to another URL in the Magento 2 platform. There are five main kinds of redirects which we’re going to look at in this blog.
First, let’s understand what is redirection! A redirect is a way to turn both users and search engines to a different URL than the original request. Magento 2 supports various types of SEO redirects, each serving specific purposes.
Let’s explore how to create and use Magento 2 Redirection in this blog.
ON THIS PAGE
What are the Types of Magento 2 SEO Redirects?
1. 301 Redirect (Permanent Redirect)
301 redirect is used to permanently redirect traffic from one URL to another. It passes the majority of the SEO value (link equity) from the old URL to the new one. It’s one of the most SEO-friendly redirects for permanent changes.
Commonly used for:
- Removing old pages.
- Merging similar content.
- Updating URLs to more SEO-friendly formats.
2. 302 Redirect (Temporary Redirect)
It indicates a temporary change in the URL, and it does not transfer link equity to the new URL.
Typically used for:
- Temporary site changes.
- Testing a new page without impacting SEO.
3. 303 Redirect (See Other)
303 redirect indicates that the requested resource can be found at another URL via a GET request. It is not commonly used for SEO purposes, as it’s intended for forms and other non-GET requests.
It’s used for:
- Redirecting after form submissions to prevent resubmissions.
4. 307 Redirect (Temporary Redirect)
This redirect is used to redirect Temporary that preserves the request method (e.g. POST remains POST). It’s similar to a 302 redirect; does not pass full link equity.
It’s used for:
- Temporary maintenance pages.
- Temporary URL changes with the same request method.
5. 410 Status Code (Gone)
It indicates that the requested resource is no longer available and will not be available again. It informs search engines to remove the URL from their index, which can be more efficient than a 404 for permanent removals.
It’s used for:
- Removing outdated content permanently.
- Handling expired product pages without alternatives.
Magento How To Create Magento 2 Redirection from Admin Panel: URL Rewrite Management?
In the Magento 2 Admin Panel
- Go to Marketing > SEO & Search > URL Rewrites.
You can do the following
- Create a New URL Rewrite: Define custom redirects for products, categories, or CMS pages.
- Edit Existing URL Rewrites: Modify automatically generated or previously added rules.
Fields include
- Store: Apply the rewrite to specific store views.
- Request Path: The original URL that needs redirection.
- Target Path: The destination URL where the user should be redirected.
- Redirect Type: Choose between 301 or 302 redirects.
Description: Add any description of redirection.
Create URL Rewrite Types
There are four types of URL rewrite types.
1. Custom (URL Rewrite Redirect)
It allows for the manual redirection of one URL to another within Magento.
It’s useful for mapping specific old URLs to new ones, especially after a site structure update.
2. For Category
It redirects a removed or outdated category to a new or related category.
Helps users find similar products without encountering 404 errors.
3. For Product
It redirects individual product URLs, especially when products are discontinued or replaced.
It ensures users are directed to related products or a category page instead of a broken link.
4. For CMS Page
It redirects old CMS pages (like blog posts or information pages) to updated or new CMS pages.
It maintains SEO value and user experience.
What are the Steps To Create 301 or 302 Redirects in Magento 2?
Method 01: Steps to Create 301 or 302 Redirects Programmatically
- Inject Required Dependencies: Inject the UrlRewriteFactory and UrlRewriteResource into your class.
- Use the UrlRewriteFactory to create a new URL rewrite entity.
- Set the redirect type to 301 and define the source and target URLs.
Example Code:
<?php
/**
* Klizer
*
* @category Klizer
* @package Klizer_Redirect
* @copyright Copyright © 2025 Klizer. All rights reserved.
* @author Klizer - info@klizer.com
*/
namespace Klizer\Redirect\Model;
use Magento\Framework\App\Action\Context;
use Magento\UrlRewrite\Model\UrlRewriteFactory;
use Magento\UrlRewrite\Model\ResourceModel\UrlRewrite as UrlRewriteResource;
class Redirect
{
/**
* @var \Magento\UrlRewrite\Model\UrlRewriteFactory
*/
protected $urlRewriteFactory;
/**
* @var \Magento\UrlRewrite\Model\ResourceModel\UrlRewrite as UrlRewriteResource
*/
protected $urlRewriteResource;
public function __construct(
UrlRewriteFactory $urlRewriteFactory,
UrlRewriteResource $urlRewriteResource
) {
$this->urlRewriteFactory = $urlRewriteFactory;
$this->urlRewriteResource = $urlRewriteResource;
}
public function createRedirect($sourceUrl, $targetUrl)
{
try {
// Create a new URL rewrite
$sourceUrl = 'old-url';
$targetUrl = 'new-url';
$urlRewrite = $this->urlRewriteFactory->create();
$urlRewrite->setStoreId(1) // Specify the store ID
->setIsSystem(0) // 0 for custom redirects
->setRedirectType(301) // 301 OR 302 redirect
->setRequestPath($sourceUrl) // Old URL
->setTargetPath($targetUrl); // New URL
// Save the URL rewrite
$this->urlRewriteResource->save($urlRewrite);
return "Redirect successfully created!";
} catch (\Exception $e) {
return "Error: " . $e->getMessage();
}
}
}
Method 02: Steps to Create 301 or 302 using the .htaccess file
Locate the .htaccess file in your Magento root directory.
Inside the .htaccess file, search for the following code block:
apache
<IfModule mod_rewrite.c>
############################################
## Enable rewrites
Options +FollowSymLinks
RewriteEngine on
Within this code block, add the following line to set up the redirection:
Redirect 301 old_url new_url
Ensure you specify the old and new URLs you want to redirect. For instance:
Redirect 301 /old-url.html /new-url.html
Save the .htaccess file after making these changes.
What are the Best Practices for Magento 2 Redirects?
- Use 301 Redirects for permanent URL changes to maintain SEO equity.
- Use 410 Status Codes for pages that are permanently removed with no replacement.
- Avoid overusing temporary redirects (302, 307) unless necessary.
- Regularly review your redirect rules to avoid redirect chains or loops.
How to Check Redirects by Tools?
These are the tools that cater to varying needs, from lightweight checks to deep technical analysis, helping optimize and troubleshoot website redirection strategies.
1. Moz: It stands out with its robust SEO reporting and research capabilities, featuring a crawl and audit system to detect and explain technical issues while offering alerts for emerging problems.
2. SEMrush: It provides a comprehensive solution, combining powerful auditing tools that pinpoint redirect chains and loops with the ability to implement fixes directly within the platform
3. RedirectChecker.org: It serves as a simple yet effective web-based tool, ideal for quickly analyzing 301 and 302 redirects, and inspecting redirect chains, HTTP headers, meta refresh tags, and JavaScript-based redirections.
4. Redirection: For WordPress users, the Redirection plugin simplifies managing 301 redirects and identifying 404 errors, enabling seamless resolution of redirect challenges across their websites.
5. ScreamingFrog: It delivers advanced functionality by crawling entire websites, utilizing a built-in redirect checker to examine response codes, uncover internal redirect chains and loops, and export data for extensive analysis
Implement Effective 301 Vs 302 Redirects in Magento 2 with Klizer
Redirection plays a crucial role in SEO by improving site navigation, preserving link equity, and enhancing user experience. Among the various types, 301 Redirects are particularly important, as they permanently guide users and search engines to updated URLs while retaining most of the original link’s SEO value.
Proper implementation of redirection ensures that search engine bots and users are not led to invalid links, ultimately boosting website traffic and maintaining a strong online presence.
For Magento expert assistance in implementing effective 301 Vs 302 redirects in Magento 2 and optimizing your site’s SEO, contact Klizer today!