Skip to content

Instantly share code, notes, and snippets.

@ckaznable
Created February 2, 2023 02:23
Show Gist options
  • Save ckaznable/a45586c5846a05a50b31f0d656e47bc7 to your computer and use it in GitHub Desktop.
Save ckaznable/a45586c5846a05a50b31f0d656e47bc7 to your computer and use it in GitHub Desktop.
rewrite old php endpoint to nextjs
import { NextRequest, NextResponse } from "next/server"
export function middleware(req: NextRequest) {
const url = req.nextUrl
// redirect php path
if (url.pathname.endsWith(".php")) {
url.pathname = url.pathname.replace("index.php", "").replace(".php", "")
return NextResponse.rewrite(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment