What is the difference between 301 and 302 redirects?

Asked

Viewed 753 times

7

I would like to know the difference between these two types of redirect code: 301 and 302.

I realized that they are called on Google’s Webmaster Tools Permanent redirection and Temporary redirection, respectively the 301 and the 302.

Questions:

  • But what’s the difference? It matters so much to redirect using one or the other?

  • For example, in a redirect when the user logs in, I should use 301 or 302?

  • What would that be "permanent"? I didn’t understand it very well. It seemed to me to be related to a url that now will always be redirected to another.

  • 2

    This sounds much more like an SEO decision. Useful links: https://seo-hacker.com/301-302-redirect-affect-seo/ http://www.stepforth.com/blog/2008/redirects-permanent-301-vs-temporary-302/

  • It means that: 302 is the shift of the employee from work to home, and 301 is when the employee is fired?

  • The analogy can be used :P 302 the employee is no longer in the service, this at home, the boss needs to talk to the employee... ask the attendant (in case google search engines) to make a call to the employee’s home. 301 the employee is no longer in the service, was fired, the boss needs to talk to the employee.... but the employee has already killed himself and can no longer be contacted :/

2 answers

5

Permanent means that the old address "no longer exists" and this new one is the "official". Temporary means that at some point the old address will return to work.

Think of a "In Maintenance" page, the redirect to it is of the temporary type, because one hour the maintenance will end.

Let’s say the company changed its name, and the site redirects to a new domain with the new company name, the redirect is permanent, the old domain may even cease to exist at some point.

The application is very flexible, are just examples, the idea is to inform the browser (and search sites like Google) how to analyze the redirection.

In many cases, really, whatever.

5


When the desired page is not in the expected location you can use 301 (for a permanent change) and 302 (for a temporary change).

Login redirects or fruit of page navigation are something else, there is a post on Soen interesting. Basically if you try to access an internal page without having logged in, it should give 4xx.

In the specification of HTTP states says (free translation):

301 - permanent change, links and future accesses should use the new url.

The requested Resource has been Assigned a new Permanent URI and any Future References to this Resource SHOULD use one of the returned Uris.

302 - found, but temporarily available at another url, the client must continue to use the original url to access this content/page.

The requested Resource resides temporarily under a Different URI. Since the redirection Might be Altered on occasion, the client SHOULD continue to use the Request-URI for Future requests.

  • The login redirect I meant is those redirects we do in the nail when the user has just logged in. For example, it just logged in, now I will redirect it to "logged/home" page. This would be 301 or 302?

  • 1

    @Wallacemaxters depends on the url. The most normal case is the redirect to be done for those who do not have access. A redirect after login done should give a 200 as it goes to a new page right? this is navigation.

  • Not to bother you too much: In the case of an already logged in user who tries to access the "login" page, however I want to "play it" to a page of who is already logged in (when he tries to access the "login" page), I would use 301?

  • 1

    @Wallacemaxters I am not HTTP expert but for me this should give a first 200, because the page in question exists and is available, and then a navigation redirect is made to another page because the login is already done; and this gives new 200 on the new page if it is online.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.