What is a 302 redirect?

What is a 302 redirect?

An experienced SEO specialist should know when and why a 302 redirect is used, and most importantly, how it differs from other types of redirects. In this article, we will analyze all the nuances of this issue, and also learn how to configure this type of redirection in different ways.

Direct Line
Who are we

Largest agency
Internet marketing outside the Moscow Ring Road:
1200+ projects
65 specialists
fourteen years on the market
TOP 10
the best online promotion companies in Russia 2020

Commercial offer

How does a 302 redirect work?

A 302 redirect works by redirecting visitors or search engine crawlers from the current URL to another. In other words, at the moment the page is loaded, a redirect response is received from the server indicating a new URL, be it 301 or 302 redirects.

What is a 302 redirect used for?

The main purpose of a 302 redirect is to create a temporary redirect of the current page to a new address. This may be needed in the following cases:

  • The page is undergoing technical work and visits by users or bots are undesirable. For example, a document is updated in stages over several days.
  • Temporary traffic redirection from one domain to another.
  • The document is subject to frequent revisions and requires showing the latest version. For example, when organizing pages of promotions in an online store, when a temporary offer appears, and the page of the previous one (as a rule, already indexed and having a certain trust) does not need to be deleted.
  • Website maintenance. In this case, the visitor is presented with a dummy screen, while the rest of the pages are not excluded from the search index.
  • Likewise, hosting providers may temporarily close certain pages on client sites.

As noted above, a 302 redirect is suitable for pages whose address has changed temporarily (as a rule, for a period of no more than 7-10 days). This indicates that the URL of the old page remains in the search engine index. Therefore, if the document has been “moved” on a permanent basis, you should only use a 301 redirect, or there may be difficulties with SEO promotion.

Some online stores set up a 302 redirect from goods that are out of stock. It is not recommended to do this, it is better to offer a potential buyer similar products, while leaving it on the original URL.

Also, do not use a 302 redirect when changing the site structure or installing an SSL certificate. This can really be a problem as the entire accumulated trust will not be transferred from the old resource, and the old pages will not be excluded from the index of search engines.

301 or 302 redirects, what’s the difference?

The main difference:

  • A 301 redirect is a permanent redirect to a new page.
  • A 302 redirect is a temporary redirect.

When it comes to the impact on SEO, there are also significant differences:

  • Unlike 301 redirects, 302 does not transfer the link “weight” of the old page to the new URL.
  • With 301 redirects, the address of the old page is removed from the search index and a new one is added. At 302, both addresses are in the index (if the new page managed to get into the index, but in any case, the old address is not excluded from it) and the “authority” of the original page is preserved.
  • If we talk about the possibility of domain gluing, then 301 allows you to do this, but 302 does not.

We advise you not to set up a 302 redirect for more than 7-10 days, otherwise sanctions from search engines may follow.

Ways to set up a 302 redirect

Setting up a 302 redirect is similar to setting up other types of redirects – the syntax and commands are the same, only the server response code is different.

Registering a 302 redirect in htaccess

This type of setting is available only on Apache servers. We find the .htaccess file in the root of the site and enter the following data into it:

RewriteEngine on
Redirect 302 /old-url https://site.ru/new-url

As you can see from the syntax, the response code (302) is indicated, then the URL of the original page, and after – the new one, indicating the connection protocol and domain name.

This example is suitable if you need to set up redirects from one page to another. If you need to create redirects within the entire resource, then you should use a more complex option:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site.ru [NC]
RewriteRule ^(.*)$ https://site /$1 [R=302,L]

To close a specific document from users and search bots, the following code is used:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/cat.html$
RewriteCond %{REMOTE_ADDR} !^
RewriteRule $ /cat.html [R=302, L]

With php

If for some reason the previous method does not work, then you can set up a 302 redirect using php code. In this case, the redirection occurs on the server itself, and not in the user’s browser.

Setting up a redirect is done by setting a special Location header and the header () function, which allows you to send an HTTP header to the browser. The main note is that this function on the page must be called before others, and be located at the beginning of the document (even a space before this construction will make it inoperable). If this rule is neglected, then the redirect will not work.

The advantage of this method of setting up a redirect is that the syntax is pretty simple:

header('Location: https://site.ru/primer.html');

To set up the redirect itself, this code fragment must be inserted into the page (in its php code), from which the redirection will be carried out to the very beginning of the document. The code example only needs to replace the URL of the destination page that will be redirected to with the full path.

If you plan to have a lot of redirects, it is recommended to create a file containing all the necessary rules.

Using JavaScript

This is a less common way of setting up a 302 redirect, because if the visitor has JavaScript disabled in the browser (which is the case in most cases), the redirection will not work.

Also, there is a slight delay caused by the fact that the original HTML page is initially loaded in the form of a white screen, and only after that the redirect is triggered.

To implement this method, you need to style the following code in the or tag of the page from which you want to redirect:

<script type=”text/JavaScript”>
document.location = ‘https://site.ru/primer.html’;

How to fix a 302 redirect to a 301?

To avoid problems, it is necessary to distinguish between these two types of redirects, to understand in which cases one or the other is applied. Sometimes there are situations when some CMS or their plugins, instead of a 301 redirect, put down a 302. This can create a number of difficulties for the resource owner, so it is important to keep track of this moment.

Methods for fixing a 302 redirect to a 301 differ depending on the method used to implement the redirect. For example, if this was done in the .htaccess file, then it is enough to simply change the server response code from 302 to 301:

RewriteEngine on
Redirect 301 /old-url https://site.ru/new-url

If we talk about the php method, in the example above, the Location header was used, by default it sends a 302 redirect. If you need to register 301, then we use the following code (after removing it from the 302 redirect):

header("HTTP/1.1 301 Moved Permanently");
header("Location: https://site.ru/primer.html");

How to check that everything is set up correctly?

There are several ways to check the server response code and the functionality of the configured redirects.

Using Yandex.Webmaster

The Webmaster’s panel allows you to check the server response codes. To get into this tool, go to: “Tools – Check server responses”. We drive in the desired URL and get the response code.

Checking the server response using Yandex.Webmaster
Checking the server response using Yandex.Webmaster

As you can see in the example, a 302 redirect worked correctly for the page.

Manual check

If you need to check one or more pages, you can use the manual method. It is enough to go to the page from which the redirect should be made, if everything is configured correctly, then the redirection will work.

Its only drawback is that it will not be possible to understand what type of redirect worked.

Using the bertal.ru service

This service allows you to get information from the HTTP headers of documents. The principle of working with it is quite simple: copy and paste the URL address of the page of interest into the line, click “Check” and get the server response code.

Checking the server response code using the bertal.ru service
Checking the server response code using the bertal.ru service

Screaming Frog SEO

If the site has a lot of redirects and you need to find them, manual methods are of little use for this. In this case, it is recommended to use specialized software, for example, Screaming Frog SEO.

Initially, the site needs to be crawled by typing its URL into the program and running the crawler.

Getting Data Through Screaming Frog SEO
Getting Data Through Screaming Frog SEO

Next, we proceed to search for pages with a 302 redirect (or any other response code), having previously configured a filter by the corresponding column:

Setting up a filter to search for pages with a 302 redirect
Setting up a filter to search for pages with a 302 redirect

And we get a list of documents of interest.

When using a 302 redirect, you need to be extremely careful, if you use it thoughtlessly, you can only complicate the SEO promotion of the resource.

# seo
# Web development

Leave a Reply

Your email address will not be published.