fix(site): redirect trailing-slash URLs via edge function (#885)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Darius Cepulis
2026-03-11 10:49:03 -05:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 7eac2bc3a1
commit 20406a024e
2 changed files with 23 additions and 1 deletions
@@ -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: '.+/$',
};
+2 -1
View File
@@ -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}`,
})),
});
}