diff --git a/src/middleware.ts b/src/middleware.ts index 26bbcc1..88357f4 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -19,6 +19,19 @@ export function middleware(request: NextRequest) { request.headers.set("x-site-name", siteName); request.headers.set("x-meta-desc", metaDesc); + // redirect for /blog// path + const blogPathRegex = /^\/blog\/([^\/]+)(\/[^\/]*)*\/?$/; + if (blogPathRegex.test(path)) { + const newBlogPath = path.replace(/^\/blog/, "") || "/"; + return NextResponse.redirect(`${mainUrl}${newBlogPath}`, 301); + } + // redirect for /about// path + const aboutPathRegex = /^\/about\/([^\/]+)(\/[^\/]*)*\/?$/; + if (aboutPathRegex.test(path)) { + const newAboutPath = path.replace(/^\/about/, "") || "/"; + return NextResponse.redirect(`${mainUrl}${newAboutPath}`, 301); + } + return NextResponse.next({ request: { // New request headers