fix: middleware redirect /about/<slug>/

This commit is contained in:
RizqiSyahrendra 2025-03-14 21:50:48 +07:00
parent d7724c4423
commit ca697cf6f6

View File

@ -19,12 +19,18 @@ export function middleware(request: NextRequest) {
request.headers.set("x-site-name", siteName);
request.headers.set("x-meta-desc", metaDesc);
// redirect for some path
// redirect for /blog/<slug>/ path
const blogPathRegex = /^\/blog\/([^\/]+)(\/[^\/]*)*\/?$/;
if (blogPathRegex.test(path)) {
const newBlogPath = path.replace(/^\/blog/, "") || "/";
return NextResponse.redirect(`${mainUrl}${newBlogPath}`, 301);
}
// redirect for /about/<slug>/ path
const aboutPathRegex = /^\/about\/([^\/]+)(\/[^\/]*)*\/?$/;
if (aboutPathRegex.test(path)) {
const newAboutPath = path.replace(/^\/about/, "") || "/";
return NextResponse.redirect(`${mainUrl}${newAboutPath}`, 301);
}
return NextResponse.next({
request: {