From d0f29760b1df71e5be43f4c3bc7275dbba1f4d0a Mon Sep 17 00:00:00 2001 From: molebox Date: Tue, 15 Mar 2022 09:22:46 +0100 Subject: [PATCH 1/2] Added note about why Next.js used 307 and 308 status codes --- docs/api-reference/next.config.js/redirects.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index 30f7ac88c680..aad93c20d16e 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -44,6 +44,9 @@ module.exports = { - `source` is the incoming request path pattern. - `destination` is the path you want to route to. - `permanent` `true` or `false` - if `true` will use the 308 status code which instructs clients/search engines to cache the redirect forever, if `false` will use the 307 status code which is temporary and is not cached. + +> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect, from a `POST` to a `GET` request, regardless of the method used by the origin. For example, a `POST` request to `/users` to create a new user, and while using a temporary 302, would change the request method to `GET`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes, and will preserve the request methods used. + - `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only. - `locale`: `false` or `undefined` - whether the locale should not be included when matching. - `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties. From 8901cba3108195b4b6a86037e7e251f6a00efd20 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sat, 19 Mar 2022 11:42:16 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Steven --- docs/api-reference/next.config.js/redirects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index aad93c20d16e..bc3c2fd919dc 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -45,7 +45,7 @@ module.exports = { - `destination` is the path you want to route to. - `permanent` `true` or `false` - if `true` will use the 308 status code which instructs clients/search engines to cache the redirect forever, if `false` will use the 307 status code which is temporary and is not cached. -> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect, from a `POST` to a `GET` request, regardless of the method used by the origin. For example, a `POST` request to `/users` to create a new user, and while using a temporary 302, would change the request method to `GET`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes, and will preserve the request methods used. +> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect to `GET`, regardless of the original method. For example, if the browser made a request to `POST /v1/users` which returned status code `302` with location `/v2/users`, the subsequent request might be `GET /v2/users` instead of the expected `POST /v2/users`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes to explicitly preserve the request method used. - `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only. - `locale`: `false` or `undefined` - whether the locale should not be included when matching.