Nextjs - change permanent redirect status code from 308 to 301

704 Views Asked by At

I'm using next.config in order to redirect non www requests.

redirects: async () => [
 {
  source: '/:path*',
  has: [{ type: 'host', value: 'example.com' }],
  destination: 'https://www.example.com'/:path*',
  permanent: true,
 },  
]

Now as you can see permanent property set to true which returns status code 308. Is there any way to change the status code to - 301?

2

There are 2 best solutions below

0
On

Change permanent value to false

0
On

308 (moved) and 307 (temporarily moved) are the more precise status codes. most browsers understand 307/308 in the meantime. Only Internet Explorer-Legacy has some issues with it.

The issue was, that with a 301, the browser switched to a GET-request while with a 308 the browser keeps the original request-type (such as PUT/POST/etc).

https://serverfault.com/a/897923

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308