From 27b80619b9cb4ca0b61b907c60a9bd96f583d370 Mon Sep 17 00:00:00 2001 From: Artur Fracala Date: Tue, 21 May 2024 12:29:59 +0200 Subject: [PATCH 1/2] delete trailing slashes --- middleware.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 middleware.js diff --git a/middleware.js b/middleware.js new file mode 100644 index 000000000..fdc8188ac --- /dev/null +++ b/middleware.js @@ -0,0 +1,10 @@ +import { NextResponse } from "next/server"; + +export function middleware(request) { + const url = request.nextUrl.clone(); + if (url.pathname.endsWith("/") && url.pathname.length > 1) { + url.pathname = url.pathname.slice(0, -1); + return NextResponse.redirect(url, 308); + } + return NextResponse.next(); +} From 6be076e3830bb36729964179c00e47747e453f5d Mon Sep 17 00:00:00 2001 From: Artur Fracala Date: Wed, 22 May 2024 09:55:01 +0200 Subject: [PATCH 2/2] wip --- next.config.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/next.config.js b/next.config.js index 8f312cd62..5d0e4c1e3 100644 --- a/next.config.js +++ b/next.config.js @@ -5,6 +5,15 @@ const withYaml = require("next-plugin-yaml"); const nextConfig = { target: "serverless", basePath: process.env.CONTEXT === "deploy-preview" ? "" : "/docs", + async redirects() { + return [ + { + source: "/:path*/", + destination: "/:path*", + permanent: true, + }, + ]; + }, }; module.exports = withPlugins(