Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Skip trailing slash redirects

Blue Mouse5c25340926ea
diff --git a/docs/middleware.ts b/docs/middleware.ts
new file mode 100644
index 000000000..ca31bdb28
--- /dev/null
+++ b/docs/middleware.ts
@@ -0,0 +1,13 @@
+import { NextResponse } from "next/server";
+import type { NextRequest } from "next/server";
+
+export function middleware(request: NextRequest) {
+ const { pathname } = request.nextUrl;
+
+ // Strip trailing slash for all paths except the root
+ if (pathname !== "/" && pathname.endsWith("/")) {
+ const url = request.nextUrl.clone();
+ url.pathname = pathname.slice(0, -1);
+ return NextResponse.redirect(url, 308);
+ }
+}
diff --git a/docs/next.config.mjs b/docs/next.config.mjs
index 4c465070d..013a5a668 100644
--- a/docs/next.config.mjs
+++ b/docs/next.config.mjs
@@ -5,7 +5,7 @@ const withMDX = createMDX();
/** @type {import('next').NextConfig} */
const config = {
basePath: "/docs",
- trailingSlash: true,
+ skipTrailingSlashRedirect: true,
reactStrictMode: true,
turbopack: {
root: import.meta.dirname,