9

The question is in the title - what causes a HTTP 302?

James Cushing
  • 718
  • 1
  • 9
  • 18
Gary Ryan
  • 744
  • 3
  • 8
  • 19

5 Answers5

10

It's a redirection, not an error. RFC2616 describes it as indicating:

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.

Note that you should only use HTTP 302 redirects for temporary redirections, not permanent ones. Permanent redirections should be implemented using an HTTP 301, instead.

You can avoid it by not issuing an HTTP 302 redirect in your code.

Find more information in the Wikipedia article, and in the answers to this related question.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    Thanks, I'm a little unsure what this means. Is the browser requesting a URI from the server, and the server is telling the browser that the requested resource has moved. – Gary Ryan Mar 25 '11 at 11:26
  • 1
    @Gary: Yes, that's exactly what it means. The browser sends back an HTTP 302 code, which means that the requested resource has temporarily moved to a different location. Along with the HTTP 302 code, the server sends back the *new* location of the item. Most browsers handle this seamlessly, receiving the message and instantly redirecting the user to the new location. – Cody Gray - on strike Mar 25 '11 at 11:45
  • 1
    @Cody Forgive me for being thick, but what causes a resource to temporarily move? – Gary Ryan Mar 25 '11 at 12:57
  • 3
    @Gary: Generally, a 302 redirect will happen because the person administering the website configured it that way. One example of a possible reason for this would be to create a temporary A/B split test of a new page, though this is not the only (or necessarily the best) way to do an A/B split. – Brian Mar 28 '11 at 15:07
  • 1
    @Gary: Yeah, Brian's answer is correct. Anything could cause a resource to temporarily move, but an HTTP 302 redirect only happens when the webmaster sets it up. You might have temporarily moved servers to do an upgrade or something like that, so you'll temporarily redirect all of your visitors to another temporary server. But it's always going to be something the webmaster or administrator is in control of. A redirect, HTTP 302 or otherwise, won't happen without your knowledge. – Cody Gray - on strike Mar 29 '11 at 03:03
  • 1
    @Brian @Cody Gray: Thanks so much, this make sense. My host are switching servers. – Gary Ryan Mar 29 '11 at 07:26
4

It's redirection somewhere of your code may set the limits to that cause the problem in a nutshell, it's all about your code

Robin Hwang
  • 189
  • 1
  • 9
1

See the guidance on w3.org.

It's actually a temporary URI redirection. It is also very common to see this when using ASP.NET - performing a server side Response.Redirect() will result in a 302.

Sir Crispalot
  • 4,792
  • 1
  • 39
  • 64
1

One reason you may get the http 302 code is if you access a https url using http.

In that case, switch to https and it will work.

jmarina
  • 333
  • 1
  • 2
  • 8
0

If you are using CodeIgniter please check url helper and find 302 replace this with 301. This is the main issue for CI based 302 redirects if we use hooks.