The question is in the title - what causes a HTTP 302?
4 Answers
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.
-
2Thanks, 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. Mar 25, 2011 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. Mar 25, 2011 at 11:45
-
1@Cody Forgive me for being thick, but what causes a resource to temporarily move? Mar 25, 2011 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.– BrianMar 28, 2011 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. Mar 29, 2011 at 3:03
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
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.
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.