HTTP 302 Found vs 307 Temporary Redirect
Both 302 and 307 indicate temporary redirects, but they handle HTTP methods differently. A 302 allows clients to change the method (POST to GET), while 307 strictly preserves the original method. 307 was introduced to resolve the ambiguity in how clients implement 302.
Descrição
The resource temporarily resides at a different URL. The client should continue using the original URL for future requests.
Quando você o vê
During A/B testing, temporary maintenance pages, or geo-based redirects.
Como corrigir
Follow the Location header. Note: browsers may change POST to GET on redirect.
Descrição
The resource temporarily resides at a different URL. Unlike 302, this guarantees the HTTP method will NOT be changed.
Quando você o vê
When you need a temporary redirect that preserves the request method (POST stays POST).
Como corrigir
Follow the Location header using the same HTTP method.
Diferenças principais
302 may change POST to GET — browsers historically convert the method despite the spec saying otherwise.
307 guarantees the HTTP method is preserved — POST stays POST with the same body.
Both are temporary, so search engines continue indexing the original URL.
307 was defined in HTTP/1.1 (RFC 7231) specifically to fix the 302 method ambiguity.
302 is more widely used in practice, but 307 is more correct for method-sensitive redirects.
Quando usar qual
Use 302 for simple temporary redirects where method preservation does not matter (e.g., redirecting to a login page). Use 307 when the HTTP method must be preserved during the redirect, such as temporarily moving a form submission endpoint or an API route.