Repository navigation
fix: redirect outdated post slugs to the current one - #7002
Merged
Merged
Conversation
The slug follows the post title, so editing a title left every shared and indexed link on a slug that no longer exists. The API now resolves outdated slugs by their trailing id (dailydotdev/daily-api#4468); the page answers them with a permanent redirect to the current slug so search engines move the URL over. Requests by id or by the current slug render as before.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Problem
A post slug follows its title (
<title>-<id>), so editing a title breaks every shared link and indexed URL that used the old slug.Fix
/posts/[id]getStaticProps: if the post comes back with a slug and the requested param is neither its id nor its current slug, we return a permanent redirect to/posts/<current slug>(revalidate: 60). Search engines then move the old URL over to the new one. Requests by id or by the current slug render as before, so the id URLs used by the post modal don't change.Depends on dailydotdev/daily-api#4468. Until that's deployed, the API returns NOT_FOUND for old slugs and the page still 404s. Merging this first is harmless.
Notes
permanent: trueas a 308. Google treats it the same as a 301.getStaticPropsdrops query params (for example UTM tags) on old-slug links. Old links resolve again, but those params are lost on the hop.Tests
PostStaticProps.spec.ts: an old slug redirects without fetching comments; the id and the current slug still render. The fixture id is nowpost-idso the existing tests keep requesting the post by its id.typecheck-strict-changedpass.🤖 Written by Smith (AI) on behalf of @idoshamun
Preview domain
https://fix-post-outdated-slug-redirect.preview.app.daily.dev