fix: middleware redirect /blog/<slug>/

This commit is contained in:
RizqiSyahrendra 2025-03-14 21:47:15 +07:00
parent d56ad18426
commit d7724c4423

View File

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