diff --git a/src/index.ts b/src/index.ts index 37870f1..0b8a13a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -174,6 +174,12 @@ export default { const url = new URL(request.url); const path = url.pathname; + // Normalize trailing slashes (except root) with a redirect + if (path !== "/" && path.endsWith("/")) { + url.pathname = path.replace(/\/+$/, ""); + return Response.redirect(url.toString(), 301); + } + // Handle CORS preflight if (request.method === "OPTIONS") { return new Response(null, {