3 ms·
Using a numeric ID + ignored path part is easy to implement, but actually using the textual part without an exposed ID seems more elegant to me. Tip for impleme
by pornel 2y ago
Using a numeric ID + ignored path part is easy to implement, but actually using the textual part without an exposed ID seems more elegant to me. Tip for implementing that:
* have a separate table that maps slugs to IDs, allowing many-to-one relationship, because content's title will be updated, and you don't want to break old links.
* long slugs will get truncated by users. A zero-cost way to recover from that is `select id where slug >= ? order by slug limit 1`
* in either case don't forget to redirect to the canonical URL, so that people can't create duplicate or misleading URLs on your site.
- lifthrasiir 2y agoI don't like slug-only URLs because they are hard to make concise. If the textual part can be compressed into one or two words, like what qntm does in his website, then it is okay, but most schemes do not really care much about slugs...
- deleted 2y ago[deleted]
- RugnirViking 2y agothe problem with that, as mentioned in the article, is that that breaks if the content of the page changes. So on stack overflow for example, what happens if someone changes the title of their question? you either break the url or use an old version of the title, thus being misleading.
- atlintots 2y agothat's what the many-to-one slug-to-id mapping is for
- oneeyedpigeon 2y agoChanging the title of the question is the real wtf.