Skip to content

Commit

Permalink
Handle v[x] redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
chadokruse committed Jan 14, 2025
1 parent f781559 commit 2e57081
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions apps/web/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -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',
};

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/routes/profiles/v1/[ein]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2e57081

Please sign in to comment.