• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Archives for Netlify

Netlify

Redirections in Netlify

npm i -D @netlify/edge-functions
netlify/edge-functions/legacy-category-redirect.ts
import type { Config } from '@netlify/edge-functions';

const MAP: Record<string, string> = {
'/hello-world': '/category/hello-world',
'/sample-post': '/category/sample-post',

};

export default async (request: Request, context: { next: () => Promise<Response> }) => {
const url = new URL(request.url);

// /something/ -> /somethin
const path = url.pathname.replace(/\/+$/, '') || '/';

const target = MAP[path];
if (!target) {
return context.next();
}

url.pathname = target;

return new Response(null, {
status: 301,
headers: {
location: url.toString(),
'x-legacy-redirect': '1', // debug
},
});
};

export const config = {
path: [
'/hello-world',
'/sample-post',
],
};

Filed Under: Angular, Netlify

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved