301 vs 302 Redirects in Magento 2: How to Create & Best Practices
Vinh Jacker | 11-11-2024
Redirection is the process of forwarding a URL to another URL. There are two main kinds of redirects: 301 Redirect and 302 Redirect.
A redirect is a way to turn both users and search engines to a different URL than the original request. Let’s explore how to create and use Magento 2 Redirect 301 vs 302 in this blog.
Without further ado, let’s dig into it!
Why a website needs redirects?
Redirects are like redirecting visitors and crawlers to another URL, which is extremely important in SEO. More than that, it is essential to keep your UX point in case of inconvenience as:
- Page or post get deleted
- CMS gets tweaked
- Change the domain of the website
- Consolidate websites
- The preferred URL change (www vs. no www)
- Web structure rework
What are 301 and 302 redirects?
301 Moved Permanently
A 301 redirectis a permanent redirect. It returns the 301 error code in the header to inform the search engine or browser that the current web page has been moved to the new address. In most cases, 301 redirects are the best way to perform redirections on a web page.
When to Use 301 Redirects
301 redirects serve various purposes and are particularly essential in specific scenarios, such as when you want to change your site URL permanently. Other common situations include:
- Permanently migrating your content to a new domain.
- Transitioning your website from HTTP to HTTPS.
- Permanently consolidating multiple websites or pages under a new web address.
- Implementing a permanent change to the URL structure on your website.
- Addressing non-www or www duplicate content issues effectively.
In essence, 301 redirects are the appropriate choice for changes intended to be enduring. If the redirection is not meant to be permanent, exploring the use of a 302 redirect is recommended instead.
302 Found (HTTP 1.1) / Moved Temporarily (HTTP 1.0)
A 302 redirect is a temporary redirect. 302 Redirect notices the page has been moved, but the client must continue to use the old URL path. You can use 302 Redirect when you want to switch hosts, technical maintenance, or conduct major changes on the website but still want visitors to access the content of the Website. The most convenient way is that you can put all your content on a different server domain, and use a 302 Redirect to direct customers to this new page, while informing the search engine that the change is only temporary for the duration of your website maintenance.
302 Redirect is very convenient in this case and the search bots of Google clearly understand the meaning of 302 Redirect. You should use 302 Redirect in case of temporary migration instead of permanently switching to 301 Redirect.
When to Use 302 Redirects
People don’t usually use 302 redirects as much as 301 redirects, so, keep that in mind. 302 redirects are normally chosen in specific instances, including
- Running a temporary promotion and redirecting website visitors to a dedicated sales page.
- Conducting A/B split tests to evaluate the design and functionality of a new website or page.
- Redirecting users to the appropriate version of a site based on their preferred language or location.
- Seeking feedback on a new page or design without influencing the current SEO rankings of the old site design.
302 redirects prove invaluable when seeking temporary feedback or testing a new design, making them suitable for situations where the changes are not intended to be permanent. Any scenario involving a short-term adjustment or when the old page is slated for reuse is typically suitable for a 302 redirect.
301 vs. 302 Redirects: Which to Choose?
Both 301 and 302 redirects serve distinct purposes, and neither is inherently superior to the other.
From a user’s perspective, the difference is often inconspicuous, and most individuals won’t notice unless explicitly informed about a temporary or permanent URL change. With a 301 redirect, the new URL gets cached by the visitor’s browser, offering potential benefits.
However, the choice of redirect does matter to search engines. 302 redirects are processed swiftly, whereas 301 redirects take more time. Consequently, if you mistakenly implement a 301 redirect and later need to revert to an old URL, it might take months for search engines to acknowledge the changes.
In short:
-
301 redirects are tailored for permanent changes. They are appropriate when you want the new URL to be indexed, and there’s no intention to switch back.
-
302 redirects are designed for temporary changes. They are preferable when the alteration is not permanent, and you might revert to the old URL in the future.
Consider the goals for your content when deciding between a temporary or permanent redirect. If you aim to establish a new URL and want it indexed, a 301 redirect is suitable. On the other hand, if you anticipate switching back, a 302 redirect is the more fitting choice.
How To Generate 301 And 302 Redirect?
There are three ways to create 301 and 302 Redirect: code, default, or extension.
You can do the redirect by directly messing with your site’s coding. The command will be different based on the language your website is written in. However, no one did that. This redirect is the default of many SEO extensions. And it’s free.
The second way you can do is to redirect in the backend manually. Every host site has the ability to create a redirect at wimp for any page on the site. Now you understand the concept of 301 and 302, so you can make it the way you want.
And last but not least, you can also purchase extensions to make this quick and convenient. Currently, there are many extensions; you should consider choosing the best one for your website. Mageplaza SEO extension for Magento 2 is an ideal option if you are looking. It is an easy-to-use extension that comes with great support from technical experts.
Best Practice to Redirect For SEO Success
If you can, avoid it
Honestly, 301 vs 302 SEO redirects are hardly SEO-friendly.
First of all, the best content should be evergreen to stay solid and sit through the erosion and earthquakes that occur in the marketplace. You need a reality check right now to keep your content up to date, but if you do it right, you can save a lot of resources on that effort.
Second, and what’s more important. Redirects increase your load time for both web readers and crawlers. Therefore, while you could argue 301 surpasses SEO values, it still takes time to reposition visitors, then settles down and thrive again.
Relevancy is the key
Regardless of the past, redirects are still a must-do on your web maintenance checklist.
You just need to make it worth it, and the first step: redirect to the most relevant URL to your intended broken or changed content.
Two notoriously bad destinations for redirects are the homepage and any other page where you want to increase SEO value.
As for the redirect to the homepage, you basically just need to remove any relevance and authority that the previous URL had.
And for the unrelated page, that’s the new soft 404 for you. From visitors’ point of view, the content is entirely useless to them, and they will click back to the SERP. Then Google will consider your content as unhelpful, and, as a result, your ranking will drop. That’s why you must redirect with a keen eye on the relevancy of your content.
Avoid looping and chain reactions
This is when your redirect includes a bunch of other redirects. When there are more than 4 redirects after clicking a URL, Google will stop to prevent repeat redirects. Also, it’s bad for your page authority because of all the transitions in between. Also, there’s no help in that redirect if it goes around a circle. Check your redirect’s SEO
This article will introduce to you more about 301 Redirect which plays an important role in SEO.
Effecting of 301 Redirect
In order to prevent the users from entering that link without content or content is deleted, the connection can not be made, the 301 redirect has an important effect on Seo. It helps to navigate your website intelligently, avoiding the case of bots and users access to invalid links.
How to use 301 redirect
- You redirect an old domain name to a new one. In the process of redirecting to a new domain, you do not want the old domain to be interrupted like closing the web, reducing traffic … and that process will be seamlessly transitioned the way you set up.
- Previously, people visited your website in different URLs. And you can focus on those different URLs to the pages that you want to target more readers. You can use different 301 Redirect URLs to push back to the page you want to do SEO faster for Magento 2.
- You have many error articles links, and the article is indexed by Google. And you have to write a new article with a completely new domain name. You will use a 301 Redirect to move the defective article with the wrong domain name to the new one with the newer domain name.
- You have links that are doing SEO. Because that article has too many mistakes in the process of SEO, so you will create other subdomain sites on the same hosting with that SEO page. Then you use the 301 redirect to direct the subdomain pages to the right seo page.
How to programmatically create 301 redirects in Magento 2?
The easiest way to create a 301 redirect in Magento 2 programmatically is to insert the following code:
<?php namespace Belvg\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 ) { parent::__construct($context); $this->redirectFactory = $redirectFactory; } public function execute() { $redirect = $this->redirectFactory->create(); $redirect->setPath('https://google.com'); return $redirect; } }
<?php
namespace Belvg\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
) {
parent::__construct($context);
$this->redirectFactory = $redirectFactory;
}
public function execute()
{
$redirect = $this->redirectFactory->create();
$redirect->setPath('https://google.com');
return $redirect;
}
}
Tips to Monitor your Redirects
Verifying the correct implementation of redirects is a straightforward process, especially for smaller websites. You can assess your redirects by entering the complete URL of the original page and observing the resulting actions.
Examining for 404 Errors
Ensure the redirect is executed correctly by examining the response code, which can be either 302 or 301. Equally crucial from a user-experience standpoint is confirming that all redirects are configured properly to prevent visitors from encountering 404 errors.
While 404 codes don’t constitute redirects, they signal users that a webpage has been removed from a site, even though links to that page still exist. To identify 404 errors, access your Google Search Console account, navigate to the coverage section, and click on the 404 section to promptly identify URLs triggering this error.
Tracking the Performance of Your Page
Key Performance Indicators (KPIs) such as page visits, time spent on a page, and bounce rate gain heightened significance when monitoring redirect activity. Monitoring these metrics helps assess whether redirects are functioning as intended. If visitors still access the page intended for redirection, it indicates a potential setup or functionality issue.
Checking Redirects by Tools
For comprehensive redirect analysis, especially on larger websites, consider utilizing specialized tools:
-
Moz: Offering SEO reporting and research tools, Moz includes a crawl and audit feature for identifying and explaining technical issues, with alerts for new problems.
-
SEMrush: An all-in-one solution with auditing tools, SEMrush identifies redirect chains and loops and enables fixes within the platform.
-
RedirectChecker.org: A straightforward web-based tool for checking websites for 301 and 302 redirects, redirect chains, HTTP headers, meta refresh, and Java redirects.
-
Redirection: This WordPress plugin empowers users to manage 301 redirects, identify 404 errors, and efficiently resolve redirect issues within the depths of their websites.
-
ScreamingFrog: This tool crawls websites with its built-in redirect checker, allowing users to filter by response code, inspect internal redirect chains and loops, and export findings in bulk.
301 Redirect Strategy Mistakes to Avoid
301 redirects are a great way for SEOs and website owners to make sure visitors return the URL they entered into the search engine. 301 redirects allow website owners to move the old URL to a new URL and then point it up in the search engines, which can boost their rankings. However, there are some common mistakes that website owners often make when setting up 301 redirects that can spell disaster for your site’s ranking.
1. Set up 302 redirects between your domain instances.
Many webmasters use 302 redirects to redirect from the old domain to the new domain. However, this is not a perfect idea as it is only a temporary change. Search engines will only update their index when you stop redirecting with 302 redirects, or if you completely 301 redirect to your site’s preferred version.
2. Change the 301 redirect domain’s backlinks to another version of your site.
If you are using a 301 redirect strategy from an old domain to a new domain, you should not change the links on that old version as it will mess up all your efforts at building relevant authority. There are some exceptions to this rule, but you shouldn’t worry too much about removing more than 3-4 links on any given page. So, if you have more than 100 links on a page of your old site, get rid of them; otherwise, Google may consider them to be unnatural links or spammy links, which can lead to poor rankings for your website.
3. Use 302 redirects when moving content.
Moving or changing your web pages can be a complicated process - if you’re giving search engines a temporary change, this is fine, as long as the new URLs are complete before the changes start to be indexed. However, if you are constantly changing the content on your site by switching from version to version, then you should probably consider a permanent solution, such as a 301 redirect strategy.
4. Certain Pages Use 301 Redirects
Never use 301 redirects for these types of pages: login/logout, user profile edit pages, search results pages, 404 error pages. The reason is when Google crawls your site and sees that there are 301 redirects to these pages, then they understand that you really don’t want them to index this page or follow its links around. So if you need to take users to different versions of the search results page depending on what page they come from, just use the canonical URL tag instead.
5. The content you create is not useful
If you make a decision to set up a 301 redirect, you have to be careful about the “rewrite” so that the search engines can understand what is being redirected to. You should avoid using unrelated keywords when setting up new URLs. This is because it will only confuse Google about your real content, and it will also be ineffective or ineffective for your business goals.
6. It redirects excessively
If you frequently redirect pages to other pages on the same site, it could be considered a form of cloaking and could result in your site being banned from search results. A good example is if you have different contact page URLs, avoid forcing users to visit all or not all by 301 redirecting people to the homepage. This will lead to frustration for your visitors as they will go to different locations when the link is clicked. However, you can keep multiple links for specific content or use anchor text links along with natural link-building strategies for SEO purposes.
7. Redirect a page other than the target page.
It’s concise with the right structure and record-keeping, but make sure you redirect to the right sites. For example, a person searching for your homepage will not be taken to your store page. Maintaining this seamless transition will help correct SEO and make your site more fun. If you are thinking of reviewing all the content of the migrated site or just renovating a few old sites, Magento 301 supports redirects. You won’t have to waste time preparing this new phase, and site users will continue to discover the helpful material they’ve been looking for. Think about adding this new phase to your project.
Some notes when using 301 Redirect
- You need to set 301 Redirect between http: // and http: // www: You should agree to use a form of www: or non-www to avoid backlink dispersion, trust, pagerank … for these two addresses, Google will not treat it as one.
- Do not switch to a new domain without setting up the first 301: When redirecting to a new domain, try to 301 Redirect from the old website to your new website to transfer all the values and credentials from that old domain.
Conclusion
Redirection has important influences in SEO. 301 Redirect is one of the redirect methods that we need the most attention. Because it navigates your website well. In addition, redirection can help bots and users not access the valid links, then increase the traffics.