cms: 308-redirect old slugs to canonical URL on detail pages#17
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
york_factory PR #43 ships editable slugs with friendly_id's
:historymodule preserved — old slugs continue to resolve to the current canonical record on the CMS side. This wires up the consumer site to honor that:/memos/:slug,/toronto/memos/:slug,/posts/:slug,/builders/:slug), compare the requested slug againstslugreturned by the API. If they differ,permanentRedirect()(HTTP 308) to the canonical URL.alternates.canonicalat 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
foo→bar:/memos/foohits york_factory, friendly_id resolves via history, returns the record withslug: "bar"./memos/bar./memos/barreturns 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-storemiddleware if editors start churning slugs frequently.Test plan
<link rel="canonical">points at the canonical slug.🤖 Generated with Claude Code