7 ms·
Great post - I quite like the stackoverflow.com style of `stackoverflow.com/questions/<question-id>/<question-title>`, where <question-title> can be changed to
by yathern 9y ago
Great post - I quite like the stackoverflow.com style of `stackoverflow.com/questions/<question-id>/<question-title>`, where <question-title> can be changed to anything, and the link still works.
This allows for easy URL readability, while also having a unique ID.
In the context of this post (the library example) that would look like
library.com/books/1as03jf08e/Moby-Dick/
- loevborg 9y agoHa, I didn't realize that you could change the question title or even leave it out altogether without breaking the link. Neat!
- dom0 9y agoA bunch of news sites use similar URL parsing; they tend to not care about the "slug" either. I think this is, in the general case, the best way.
- spiderfarmer 9y agoAs long as you provide a canonical URL.
- duskwuff 9y agoOr if you redirect any non-canonical URLs to the canonical one.
- overcast 9y agoThis is the way I've always done it as well, and super easy to implement. For example. router.get('/article/:article_shortid*?',function(req,res){ }); catches /article/28424824/this-is-my-article, and also /article/28424824
- Moter8 9y agoStrangely enough, discourse uses the following style: https://meta.discourse.org/t/deleted-topics-where-are-they/22312/7 https://meta.discourse.org/t/deleted-topics-where-are-they/2... /t/ for topic, slug for readability, then a topic id and at last a reply id.
- detaro 9y agoand your comment is the perfect demonstration why: when truncated, the id gets cut off before the slug.
- TeMPOraL 9y agoWhich is... something you don't want to happen, right?
- detaro 9y agoRight, I was thinking purely display truncation, like here. Surviving copy-paste from here or other actual truncation it's bad, true.
- StavrosK 9y agoTo be fair, if you truncate a url for anything other than display, it's toast (which is why no sane person truncates URLs except for display).
- ehsankia 9y agoSo does reddit. Go to any comment section. You can remove the latter part with the title and only leave the identifier, and the link will still work. The short link actually only contains the identifier.
- nayuki 9y agoAmazon has been doing this URL scheme since many years ago, e.g.: https://www.amazon.com/Optional-product-name/dp/A00BCDEF00ID/ https://www.amazon.com/Optional-product-name/dp/A00BCDEF00ID...
- saurik 9y agoDoing this means that: 1) there are now an infinite number of URLs for every one of your pages that may end up separately stored on various services (mitigated for only some kinds of service if you redirect to correct), 2) if the title changes the URLs distributed are now permanently wrong as they stored part of the content (and if you redirect to correct, can lead to temporary loops due to caches), 3) the URL is now extremely long and since most users don't know if a given website does this weird "part of the URL is meaningless" thing there are tons of ways of manually sharing the URL that are now extremely laborious, 4) have now made content that users think should somehow be "readable" but which doesn't even try to be canonical... so users who share the links will think "the person can read the URL, so I won't include more context" and the person receiving the links thinks "and the URL has the title, which I can trust more than what some random user adds". The only website I have ever seen which I feel truly understands that people misuse and abuse title slugs and actively forces people to not use them is Hacker News (which truncates all URLs in a way I find glorious), which is why I am going to link to this question on Stack Exchange that will hopefully give you some better context "manually". meta.stackexchange.com/questions/148454/why-do-stack-overflow-links-sometimes-not-work/ Many web browsers don't even show the URL anymore: the pretense that the URL should somehow be readable is increasingly difficult to defend. A URL should sometimes still be short and easy to type, but these title slug URLs don't have that property in spades. If anything, other critical properties of a URL are that they are permanent and canonical, and neither of these properties tend to be satisfied well by websites that go with title slugs, and while including the ID in there mitigates the problem it leaves it in some confusing middle-land where part of the URL has this property and part of it doesn't. If you are going to insist upon doing this, how about doing it using a # on the page, so at least everyone had a chance to know that it is extra, random data that can be dropped from the URL without penalty and might not come from the website and so shouldn't be trusted? (edit to add:) BTW, if you didn't know you could do this, Twitter is most epic source of "part of the URL has no meaning" that I have ever run across as almost no one realizes it due to where it is placed in the URL. twitter.com/realDonaldTrump/status/247076674074718208
- simcop2387 9y agoThe usual way I've seen to deal with this kind of ambiguity is by doing a 301 redirect so that bookmarks get changed and the url in the address bar is also changed. It doesn't fix external parties linking to the site with the now deprecated url but there was never anything you could reasonably do about that. > If you are going to insist upon doing this, how about doing it using a # on the page, so at least everyone had a chance to know that it is extra, random data that can be dropped from the URL without penalty and might not come from the website and so shouldn't be trusted? The fragment doesn't get indexed by search engines so not many will see it. Along with that, in my understanding, having something human readable in the URL helps with SEO in at least google an bing so doing this could hurt your search rankings which isn't a good thing.
- digikata 9y agoThis seems like it's vulnerable to some form of abuse. library.com/books/1as03jf08e/Moby-Dick/ library.com/books/1as03jf08e/Hitchhikers-Guide-to-the-Galaxy Now lead to the same place...
- always_good 9y agoYou would redirect to the canonical one.
- WorldMaker 9y agoYou don't necessarily have to redirect, but you should at least include `<link rel="canonical" href="..." />` (as given example StackOverflow does) so that search robots and other website (scrape and/or API) clients know which one is the canonical path, to avoid duplicate efforts.
- always_good 9y agoThat only works for some crawlers. Certainly not for users. Meanwhile, everything obeys redirects. Since you bring up Stack Overflow, notice that they do the canonical redirect. Change the title in the URL and you'll get redirected.
- WorldMaker 9y agoYes, the best approach is probably both, but it is crawlers that it matters more that they know the canonical paths more than users, and a crawler ignoring rel="canonical" is likely not much better than/as buggy as a crawler ignoring robots.txt; it's a specification they can ignore at their own peril.
- awj 9y agoI think the concern is in the way it obscures the target. Replace "Moby Dick" with a Chuck Tingle (warning, probably nsfw) book. Now that second link is a serious problem.
- CydeWeys 9y agoGoodreads does something similar, which I also appreciate. An example: https://www.goodreads.com/book/show/22733729-the-long-way-to-a-small-angry-planet https://www.goodreads.com/book/show/22733729-the-long-way-to... You can take off any of the words past the numeric ID and it still works just fine.