middleware redirects
Answered
Russian Blue posted this in #help-forum
Russian BlueOP
Hi, is there a way to make redirects permanent in the middleware. That is 308 http response code.
The default behaviour of the example code from the docs is a temporary redirect, 307.
The default behaviour of the example code from the docs is a temporary redirect, 307.
// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
return NextResponse.redirect(new URL('/home', request.url))
}3 Replies
Answer
Or this (which I prefer): NextResponse.redirect(new URL(…), { status: 308 })
Russian BlueOP
Got it. Thanks so much!