Skip to content

NextResponse redirect with Header Prop #51232

You must be logged in to vote

This is one of a way to do it.

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
 
export function middleware(request: NextRequest) {
  if (request.nextUrl.pathname === '/') {
    const response = NextResponse.redirect(new URL('/test', request.nextUrl))
    response.headers.set('some-header', 'hello')

    return response
  }
}

Reference

Replies: 4 comments 9 replies

You must be logged in to vote
5 replies
@SamKomesarook

@IronBlossom

@vicky-hemnani

@LikeDreamwalker

@lukeocodes

Answer selected by SamKomesarook

You must be logged in to vote
1 reply
@LikeDreamwalker

You must be logged in to vote
0 replies

You must be logged in to vote
3 replies
@ZowWeb

@amanzrx4

@ZowWeb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
10 participants