Skip to content

cms: 308-redirect old slugs to canonical URL on detail pages#17

Merged
xrendan merged 1 commit into
mainfrom
canonical-slug-redirects
May 22, 2026
Merged

cms: 308-redirect old slugs to canonical URL on detail pages#17
xrendan merged 1 commit into
mainfrom
canonical-slug-redirects

Conversation

@xrendan
Copy link
Copy Markdown
Member

@xrendan xrendan commented May 21, 2026

Summary

york_factory PR #43 ships editable slugs with friendly_id's :history module preserved — old slugs continue to resolve to the current canonical record on the CMS side. This wires up the consumer site to honor that:

  • On every slug-based detail page (/memos/:slug, /toronto/memos/:slug, /posts/:slug, /builders/:slug), compare the requested slug against slug returned by the API. If they differ, permanentRedirect() (HTTP 308) to the canonical URL.
  • Point alternates.canonical at the canonical slug everywhere (was using the URL param), and add it to /posts/:slug, which was missing one.

The resulting flow when an editor renames foobar:

  1. /memos/foo hits york_factory, friendly_id resolves via history, returns the record with slug: "bar".
  2. TradingPost sees the mismatch, returns 308 to /memos/bar.
  3. Browser follows; /memos/bar returns 200 with <link rel="canonical" href="/memos/bar">.

Why 308 and not 307

Permanent (308) is the right call here — transfers link equity to the new URL and gets search engines to update the index. The cache-staleness trade-off (browsers cache 308s) is real but self-healing: worst case is one extra round trip on a re-rename. Discussed inline; revisit with Cache-Control: no-store middleware if editors start churning slugs frequently.

Test plan

  • Rename a memo's slug in the york_factory admin; visit the OLD URL on TradingPost; confirm 308 → new URL in network tab.
  • Repeat for a post, a builder, and a toronto memo.
  • Visit the current canonical URL; confirm 200 (no redirect loop).
  • Visit a never-existed slug; confirm 404 (not redirect).
  • View source on a detail page; confirm <link rel="canonical"> points at the canonical slug.

🤖 Generated with Claude Code

york_factory now supports editable slugs (PR #43) with friendly_id's
:history module preserved, so old slugs continue to resolve to the
current canonical record. Compare the requested slug against the
canonical slug returned by the API and permanentRedirect to the new
URL when they differ, on memos, toronto memos, posts, and builders.
Point alternates.canonical at the canonical slug in every case (and
add it to posts, where it was missing) so crawlers index the new URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xrendan xrendan merged commit f9e72e0 into main May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant