Qined Community πŸ§‘β€πŸ’»

Shajith Ali
Shajith Ali

Posted on

How and when to use 301 and 302 redirects in SEO?

Image description
301 or 302 redirects refer to it, what is it?

First of all, it is necessary to explain what a redirect is in the field of web and SEO : a redirect is a way to send both users and search engines to a different URL from the one they originally asked.

Redirections allow you to direct Google robots and optimize crawl by redirecting spiders to the right URLs following a change.

Concretely, when content has been moved or a page has been deleted, it is possible to ensure that visitors or search engines seeking this resource are redirected to a new url (on the same domain or not).

They are used by webmasters on several occasions in the life of an online site: redesign, change of the name of a site, migration and implementation of the https protocol, etc.

We talk about 301 for a permanent redirect, while we talk about 302 in the case of a temporary one.

The use of this process is widespread in SEO and makes it easy and efficient to redirect traffic from one URL to another, without compromising the user experience, while preserving the work done at the level of natural referencing.

Here are some tips for making the best use of this redirect tool, depending on the situation.

How to use 301 and 302 redirects in SEO?

As part of a site redesign, moving or deleting one or more pages, or simply for strategic reasons, they are a good tool for SEOs and webmasters.

By considering that a content is available from a url, in the context of a movement of resources for example, it is possible to ensure that when entering a site through a page, navigation is in reality redirected to another url, theoretically relevant and related to the query stated. That's the whole point of these HTTP status codes .

Whether it is temporary or permanent, its implementation makes it possible to choose the resource towards which the traffic will be directed.

301 redirects

Image description
Let's imagine that the tree structure of a site is redesigned by its designer and that it will require the displacement of certain resources. The existing urls having already succeeded in positioning themselves on certain interesting keywords, it would be a shame to lose this work by simply creating new urls .

It is therefore possible to set up redirections from the old urls to the new ones, while transferring the positions acquired by the old ones. Thus, although revamped, the website in question still offers the resources sought after by users and Google, while retaining the benefits of the previous work. It is said to pass juice from the old url to the new one.

The 301 redirect is said to be β€œpermanent” and assumes that the most recent page will supplant the old one, recovering in the process all its traffic and its positions on the SERPs. The robots will consider the new url as the main resource during the Google indexing process.

Applicable both at the scale of the internal mesh of a site, and to another domain name, the 301 is the simplest and most effective way to redirect traffic from point A to point B without see the performance of his site drop.

Very practical for dealing with 404 error pages , it directs visitors to a nearby page, thus preserving the UX of the site. Similarly, considering netlinking, it is possible to recover the juice sent to a URL that no longer exists. It is implemented to take advantage of a link pointing to an obsolete url by redirecting the link to another target page.

Note : the 301 is widely used to avoid duplicate content within the same site. Sometimes pages are very similar within the same structure. In order to avoid undesirable effects with Google, it is possible to redirect from one page to another very similar one. Thus, the destination page retains its positioning, while inheriting the positioning of the redirected page.

301 with an .htaccess file

Code to redirect a page:

RedirectPermanent /repertoire/page-a-rediriger.html http://www.domaine.com/repertoire/page-de-destination.html

Code to redirect a directory:

RedirectPermanent /repertoire http://www.domaine.com/repertoire-de-destination

Code to redirect a domain:

RedirectPermanent / http://domaine.com/

301 in PHP

The PHP code is to be integrated into the source code of the page to be redirected.

<?php
header("Status: 301 Moved Permanently", false, 301);
header("Location: http://www.domaine.com/repertoire/page.php");
exit();
?>

302 redirects

Image description
It is not used in the same type of case as the 301.

Take for example an e-commerce site that sells a certain product category. If one of its products has a seasonal version, it is quite possible to create a page dedicated to this version. However, it may be difficult to drain enough visibility quickly to ensure good sales. In this case, nothing prevents the e-merchant from temporarily redirecting visits from its category to the seasonal products page. He will do it using a 302.

url produit ==>redirection 302==> url produit d’étΓ©

Once the seasonal operation is over, all he has to do is remove it for his main category to regain its full flow of visitors.

As you will have understood, the difference between 301 and 302 lies above all in the definitive or temporary aspect of the redirection put in place . However, in either case, the goal is to submit a chosen resource to Internet users and search engine crawlers when they visit.

302 with an .htaccess file

Code to redirect a page:

Redirect /repertoire/page-a-rediriger.html http://www.domaine.com/repertoire/page-de-destination.html

Code to redirect a directory:

Redirect /repertoire http://www.domaine.com/repertoire-de-destination

Code to redirect a domain:

Redirect / http://www.domaine.com/

302 in PHP

The PHP code is to be integrated into the source code of the page to be redirected.

<?php
header("Location: http://www.domaine.com/repertoire/page.php");
exit();
?>

How to set up a 301 or 302 redirect?

Several solutions are available to you to create them.

Depending on your skills or the access you have within your site, different possibilities are possible:

  • In order to redirect an entire domain to another, the registrar's option is the easiest . All offer an interface offering you the possibility of setting up a redirection from one domain to another. Ex: mysite A.com==>mysite B.com
  • Editing files on the server: by editing the .htaccess file, you can create a redirect from one internal resource on your site to another. However, it is necessary to have access to the server and to master a certain know-how so as not to damage the functioning of your site.
  • Programming on the server: thanks to the PHP or ASP language, it is possible to program redirections. Given the knowledge necessary to intervene in this way, a developer will have to intervene to guarantee the efficiency and integrity of the operation.
  • Programming in JavaScript on the client side: using JavaScript, it is possible to set them up from one page to another. Unfortunately, this type of method does not guarantee an optimal result, as JavaScript requires interpretation from search engines.
  • The use of extensions: on a CMS like WordPress, there is more than one plugin (module or extension) allowing them to be set up. No advanced technical skills are required. You just have to carefully select the urls concerned to make sure you don't damage the structure or the efficiency of your website. This method applies above all to redirect urls within sites, not from one domain to another.

Whichever method you use, keep in mind the difference between a 301 and a 302. Don't use one instead of the other, or you won't get the desired result.

Note : a point that we have not addressed is the passage of a site from the http protocol to the HTTPS. In this case, after the installation of the SSL certificate, it will be necessary to carry out a redirection of the old urls in http, towards the new ones in HTTPS. This is the guarantee of not seeing all your natural referencing work destroyed. It will be the same for sites going from a url without β€œwwwβ€œ to the presence of β€œwwwβ€œ.

Some key points about redirects

It has been noted that in certain scenarios, they turn out to be blocking for certain factors.

For example, in the context of interactions and sharing of your resources on social networks, it is possible that a 301 does not make it possible to recover all the data relating to the effective shares. This is particularly the case with Twitter and Facebook which do not seem to transfer interactions.

Another point, it can be counterproductive to systematically redirect urls displaying 404 errors to the Home of a site . It is important to ask the question of the proximity of the redirected content and its relevance. Sending everything back to your main page could have a negative effect.

As mentioned before, in the context of netlinking, they are interesting for recovering the SEO juice of links pointing to a page that no longer exists. Again, it is preferable to create a redirect to a page whose content is close to the defunct url. The result will only be more beneficial.

The display speed is also slowed down and can harm SEO if the redirect chains slow down search engine robots. Tools allow you to test the speed of a website.

If you doubt between setting up a canonical tag or a redirect, prefer a redirect. In its guidelines, Google suggests that the redirect will be more effective, especially if it is a permanent situation.

Conclusion on 301 and 302 redirects in SEO

As you will have understood, the 301 and 302 are valuable tools , provided you respect their installation and keep in mind the effect they will have.
Whatever the method used to create them, it will be necessary above all to ensure its legitimacy, as well as its usefulness. Only then will you get the most out of these devices.

If as part of the optimization of your site you wish to use this option, without really knowing where to start, contact us. We will study together the possible possibilities in your case (redesign, migration, indexing errors, etc.).

Top comments (0)