Examples of Great URL Design (2023)
11–20 of 163 posts
Re: Examples of Great URL Design (2023)
#12What’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.
Re: Examples of Great URL Design (2023)
#13* 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.
Re: Examples of Great URL Design (2023)
#14What’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).
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
Re: Examples of Great URL Design (2023)
#15One big question in URL design is this: Do path parameters get to have / in their values? Let’s say you have a link shortener service and want to allow users to define shortcuts like /mypath/:rest where rest is appended to example.com/ Now you’re in a very interesting position when it comes to resolving URLs. Curious to hear folks with experience in this
, is encoded as %2C
/ is encoded as %2F
Re: Examples of Great URL Design (2023)
#16Shout out to the classic "Cool URIs don't change": https://www.w3.org/Provider/Style/URI
Re: Examples of Great URL Design (2023)
#17Earlier quoted context omitted.
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
> https://stackoverflow.com/questions/78870603/i-LOVE-genocide This is bad.
Re: Examples of Great URL Design (2023)
#18Earlier quoted context omitted.
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
> https://stackoverflow.com/questions/78870603/i-LOVE-genocide This is bad.
Not to mention something similar can be done to any url, e.g. #whatever-you-want or ?_=whatever-you-want
Re: Examples of Great URL Design (2023)
#19Using 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 `se…