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.
主な違い
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.
使い分け方
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.