7664a40064
## Documentation / Examples - [X] Make sure the linting passes by running `pnpm lint` - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
15 lines
455 B
TypeScript
15 lines
455 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export function middleware(request: NextRequest) {
|
|
if (request.nextUrl.pathname === '/about') {
|
|
return NextResponse.redirect(new URL('/redirected', request.url))
|
|
}
|
|
if (request.nextUrl.pathname === '/another') {
|
|
return NextResponse.rewrite(new URL('/rewrite', request.url))
|
|
}
|
|
return NextResponse.next()
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/about/:path*', '/another/:path*'],
|
|
}
|