diff --git a/apps/web/src/hooks.server.ts b/apps/web/src/hooks.server.ts index 6eba49b..b65e110 100644 --- a/apps/web/src/hooks.server.ts +++ b/apps/web/src/hooks.server.ts @@ -1,8 +1,9 @@ +import { redirect } from '@sveltejs/kit'; import type { HandleServerError } from '@sveltejs/kit'; -type Redirects = { [key: string]: string }; +type SitemapRedirects = { [key: string]: string }; -const legacySitemapRedirects: Redirects = { +const legacySitemapRedirects: SitemapRedirects = { '/sitemap-main.xml': '/sitemaps/sitemap-main.xml', }; @@ -11,7 +12,13 @@ export async function handle({ event, resolve }) { // Handle legacy sitemap redirect if (legacySitemapRedirects[path]) { - return Response.redirect(new URL(legacySitemapRedirects[path], event.url.origin), 301); + return redirect(301, new URL(legacySitemapRedirects[path], event.url.origin)); + } + + // Handle legacy profiles 'v' redirect + if (path.startsWith('/profiles/v0/')) { + const newPath = path.replace('/profiles/v0/', '/profiles/v1/'); + return redirect(301, newPath); } return resolve(event); diff --git a/apps/web/src/routes/profiles/v1/[ein]/+page.server.ts b/apps/web/src/routes/profiles/v1/[ein]/+page.server.ts index 0a7b8cc..a7ac4ce 100644 --- a/apps/web/src/routes/profiles/v1/[ein]/+page.server.ts +++ b/apps/web/src/routes/profiles/v1/[ein]/+page.server.ts @@ -106,7 +106,7 @@ export const load: PageServerLoad = async ({ params, url }) => { // Maintain existing SEO link equity by throwing a proper 301 // This results in an extra round trip, but that's OK as Cloudflare is fast and we can add aggressive caching at the API level - const canonicalPath = `/profiles/v0/${ein}-${profile.organization_name_slug}/`; + const canonicalPath = `/profiles/v1/${ein}-${profile.organization_name_slug}/`; const canonicalUrl = new URL(canonicalPath, url.origin).toString(); if (url.pathname !== canonicalPath) { return redirect(301, canonicalUrl);