A good article URL is short enough to share, descriptive enough to recognize, and stable enough to bookmark. The title may change as an article improves; the URL should not need to change with every editorial revision.
Choose and preserve identity
Generate a readable slug at creation time, then store it as the article’s public identifier. Enforce uniqueness in the database rather than relying on a preflight query that can race. If a conflict occurs, add a deterministic suffix. Do not build the canonical URL from a mutable title on every request.
When a title change truly requires a new slug, keep a redirect from the old path. Prevent redirect loops and chains by resolving old slugs directly to the current canonical route. For deleted or unpublished content, return the intended status and page behavior; do not redirect every missing slug to the home page, which hides errors from both readers and crawlers.
Make canonical metadata agree
The page’s canonical link, sitemap entry, internal links, and Open Graph URL should use the same canonical address. Normalize trailing slash and hostname behavior consistently. If the site supports locale variants, define whether each locale has a separate canonical URL or an alternate-language relationship.
Test direct navigation, refresh, renamed content, old links, duplicate slugs, and unknown slugs. A URL design is complete when readers can share a link and expect it to keep finding the intended article.
Preserve identity when a title changes
A stable article ID is useful internally, even when the public route includes an author handle and a title-based slug. Store the mapping from previously published slugs to the current route as part of the edit workflow. A rename can then keep external links useful without making a later algorithm guess which article owned the old link.
In Next.js, permanentRedirect ordinarily issues a 308 response. The same helper emits a client redirect tag during streaming and returns 303 when called in a Server Action. Test the response for the route and request type you actually expose. In DevShareHub's public blog, the author-and-slug path identifies the reader-facing article, so publishing a new slug should also update the canonical value and internal links. Next.js permanent redirect API
Worked example
Choose canonical identity on the server. Keep mappings for older slugs so renaming an article does not invalidate links already shared with readers.
tsinterface ArticleLink { slug: string; username?: string | null; } function articlePath(article: ArticleLink): string { const slug = encodeURIComponent(article.slug); return article.username ? `/blog/${encodeURIComponent(article.username)}/${slug}` : `/blog/${slug}`; }




Community
Discussion
Loading comments…