Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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).


/page/:id/:slug-you-ignore, as in TFA. The id doesn't change, and the slug can be anything.


Rather than totally ignoring the slug, I prefer sending a 302 to the correct slug if the slug is absent or incorrect.


The 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



No 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.


It’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.


What 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





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: