From 20406a024efa2c190f8e4f11a1d76c87efb7628d Mon Sep 17 00:00:00 2001 From: Darius Cepulis Date: Wed, 11 Mar 2026 10:49:03 -0500 Subject: [PATCH] fix(site): redirect trailing-slash URLs via edge function (#885) Co-authored-by: Claude Opus 4.6 --- site/netlify/edge-functions/trailing-slash.ts | 21 +++++++++++++++++++ site/src/pages/rss.xml.js | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 site/netlify/edge-functions/trailing-slash.ts diff --git a/site/netlify/edge-functions/trailing-slash.ts b/site/netlify/edge-functions/trailing-slash.ts new file mode 100644 index 00000000..d2807552 --- /dev/null +++ b/site/netlify/edge-functions/trailing-slash.ts @@ -0,0 +1,21 @@ +import type { Config } from '@netlify/edge-functions'; + +export default async (request: Request) => { + const url = new URL(request.url); + const redirectUrl = new URL(url.pathname.replace(/\/$/, ''), url.origin); + redirectUrl.search = url.search; + redirectUrl.hash = url.hash; + + return new Response(null, { + status: 301, + headers: { + location: redirectUrl.toString(), + 'cache-control': 'public, max-age=86400', + }, + }); +}; + +export const config: Config = { + cache: 'manual', + pattern: '.+/$', +}; diff --git a/site/src/pages/rss.xml.js b/site/src/pages/rss.xml.js index 204f5594..76f05ce4 100644 --- a/site/src/pages/rss.xml.js +++ b/site/src/pages/rss.xml.js @@ -9,9 +9,10 @@ export async function GET(context) { title: SITE_TITLE, description: SITE_DESCRIPTION, site: context.site, + trailingSlash: false, items: posts.map((post) => ({ ...post.data, - link: `/blog/${post.id}/`, + link: `/blog/${post.id}`, })), }); }