HTTP

HTTP 307 Temporary Redirect vs 308 Permanent Redirect

Both 307 and 308 preserve the HTTP method during a redirect, but they differ in permanence. A 307 is temporary (the client should keep using the original URL), while a 308 is permanent (the client should update its references to use the new URL).

描述

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.

描述

The resource has been permanently moved. Like 301, but guarantees the HTTP method will NOT be changed.

何时出现

For permanent URL changes where POST requests must remain POST.

如何修复

Update all references to the new URL. The HTTP method is preserved.

主要区别

1.

307 is temporary — browsers do not cache the redirect and the original URL remains canonical.

2.

308 is permanent — browsers cache the redirect and search engines transfer ranking to the new URL.

3.

Both preserve the HTTP method and request body, unlike 301/302 which may rewrite POST to GET.

4.

307 is ideal for maintenance windows or temporary API migrations.

5.

308 is ideal for permanent API endpoint renames where clients send non-GET requests.

何时使用哪个

Use 307 for temporary method-preserving redirects such as maintenance rerouting or load balancing. Use 308 for permanent method-preserving redirects such as API versioning or endpoint renames. Think of 307 as the temporary counterpart to 308, just as 302 is the temporary counterpart to 301.

了解更多