15 ms·
What’s the best way to handle url slugs that change? For example, if I have www.example.com/page/foo, and the user changes that page’s title to bar, the slug up
by aejm 2y ago
What’s the best way to handle url slugs that change? For example, if I have www.example.com/page/foo, and the user changes that page’s title to bar, the slug updates to www.example.com/page/bar and anyone visiting the old url gets automatically redirected to the new one. But now the old slug of foo can’t be used again (without appending some unique identifier to it, like foo-th683gh9i).
- msoad 2y agoThe first example is just that. Put the id in the URL and make the slug optional. Stackoverflow makes the slug completely optional but you have the choice of only accepting foo and bar in your example
- Traubenfuchs 2y ago> https://stackoverflow.com/questions/78870603/i-LOVE-genocide https://stackoverflow.com/questions/78870603/i-LOVE-genocide This is bad.
- christina97 2y agoNo you redirect to the right place. It’s no worse than writing obscene things in a URL fragment (after #) that doesn’t even get sent to the server.
- hmry 2y agoWhat is the actual harm in allowing people to put random text at the end of the url? Not to mention something similar can be done to any url, e.g. #whatever-you-want or ?_=whatever-you-want
- alpinisme 2y agoIt’s not great but it matters less when the content you get going to that page is so unremarkable. Don’t forget you can do that to any url, even of sites that don’t use optional slugs, if your goal is just vague, evil-by-link-appearance.
- layer8 2y agoThis is not materially different from https://stackoverflow.com/questions/78870603#i-LOVE-genocide https://stackoverflow.com/questions/78870603#i-LOVE-genocide or https://stackoverflow.com/questions/78870603?i-LOVE-genocide https://stackoverflow.com/questions/78870603?i-LOVE-genocide.
- isoprophlex 2y ago/page/:id/:slug-you-ignore, as in TFA. The id doesn't change, and the slug can be anything.
- deleted 2y ago[deleted]
- cthor 2y agoRather than totally ignoring the slug, I prefer sending a 302 to the correct slug if the slug is absent or incorrect.