Live data from Hacker News

Examples of Great URL Design (2023)

blog.jim-nielsen.com

11–20 of 163 posts

Re: Examples of Great URL Design (2023)

#11
I can't check this because I'm on mobile, but I presume Stack Overflow uses a canonical tag in the HTML to state their preference that the longer version with the slug should be the default, because that's the one search engines use.

Re: Examples of Great URL Design (2023)

#12
post #3

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.

[deleted]

Re: Examples of Great URL Design (2023)

#13
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.

Re: Examples of Great URL Design (2023)

#14
post #5
post #3

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

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)

#15
post #10

One 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

As per RFC 3986 [1], reserved characters such as , and / must be URL encoded.

, is encoded as %2C

/ is encoded as %2F

[1] https://www.rfc-editor.org/rfc/rfc3986

Re: Examples of Great URL Design (2023)

#17
post #5

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

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.

Re: Examples of Great URL Design (2023)

#18
post #5

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

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

Re: Examples of Great URL Design (2023)

#19
post #13

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 `se…

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

Re: Examples of Great URL Design (2023)

#20

Shout out to the classic "Cool URIs don't change": https://www.w3.org/Provider/Style/URI

... and the classic Penisland: https://www.penisland.net/

I was once linked fagasstraps.com on an IRC channel and I expected something else.
Post reply on HN