HTTP

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.

Описание

The resource temporarily resides at a different URL. The client should continue using the original URL for future requests.

Когда вы это видите

During A/B testing, temporary maintenance pages, or geo-based redirects.

Как исправить

Follow the Location header. Note: browsers may change POST to GET on redirect.

Описание

The resource temporarily resides at a different URL. Unlike 302, this guarantees the HTTP method will NOT be changed.

Когда вы это видите

When you need a temporary redirect that preserves the request method (POST stays POST).

Как исправить

Follow the Location header using the same HTTP method.

Ключевые различия

1.

302 may change POST to GET — browsers historically convert the method despite the spec saying otherwise.

2.

307 guarantees the HTTP method is preserved — POST stays POST with the same body.

3.

Both are temporary, so search engines continue indexing the original URL.

4.

307 was defined in HTTP/1.1 (RFC 7231) specifically to fix the 302 method ambiguity.

5.

302 is more widely used in practice, but 307 is more correct for method-sensitive redirects.

Когда что использовать

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.

Узнать больше