Created
September 13, 2023 01:14
-
-
Save margauxflores/636bb1a7fb288a89771d7b54b1b170bc to your computer and use it in GitHub Desktop.
Next.js Redirect All Pages to Index Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextResponse, type NextRequest } from 'next/server'; | |
export function middleware(req: NextRequest) { | |
const { pathname } = req.nextUrl; | |
if (pathname == '/') { | |
return NextResponse.next(); | |
} | |
return NextResponse.redirect(new URL('/', req.url)); | |
} | |
export const config = { | |
matcher: '/((?!api|_next|static|public|images|favicon.ico).*)', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment