112

Many websites, including this one, add what are apparently called slugs - descriptive but as far as I can tell useless bits of text - to the end of URLs.

For example, the URL the site gives for this question is:

https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls

But the following URL works just as well:

https://stackoverflow.com/questions/47427/

Is the point of this text just to somehow make the URL more user friendly or are there some other benefits?

Pang
  • 8,605
  • 144
  • 77
  • 113
Dave Webb
  • 179,733
  • 56
  • 298
  • 296
  • 44
    slugs serve as URL's Caller ID Name. When you get a phone call, knowing the person's name isn't necessary, but it helps you decide whether you want to pick up the phone or not. Likewise, a URL slug helps the user decide if they want to click on the link and gives it some intrinsic context. – Armstrongest Mar 15 '10 at 18:30
  • 4
    ^^ +1, but it'd have been better to see your reply as an Answer rather than a comment.. – Dienekes Oct 24 '10 at 17:20
  • helps with rankings in search engine results. – Jay Smoke Jul 27 '15 at 00:26
  • http://stackoverflow.com/q/47427 also works :P – Mohammed H Feb 21 '16 at 14:15

14 Answers14

167

The slugs make the URL more user-friendly and you know what to expect when you click a link. Search engines such as Google, rank the pages higher if the searchword is in the URL.

Espo
  • 39,502
  • 20
  • 127
  • 156
  • 3
    One of the things that make a url user-friendly is 'discover-ability', meaning you can take a guess at url's simply from the address bar. http://i.love.pets.com/search/cats+dogs could easily lead to http://i.love.pets.com/search/pug+puppies etc – Xian Sep 06 '08 at 13:51
  • 13
    Xian, I've heard that argument before, but I don't think it stands up to scrutiny. Apart from geeks, hardly anyone really types URLs directly. Readability is definitely important, and I think a growing number of users *see* the URLs, but when it comes to "guessing" I think the minority is extremely tiny. – eyelidlessness Jun 02 '09 at 15:59
  • 4
    @eyelidlessnes - I will have to disagree. While people might not manually enter URLs, I have seen evidence that they create them. Through looking at our logs and our monitoring devices, we see samples where one user session will do something and then modify the URL (evidenced by the lack of a referrer). Granted, not everyone is doing it - but it definitely is not a negligible amount of traffic. – Joseph Ferris Aug 30 '09 at 22:52
  • @Xian. Yes, few type URLS, however, the slug is essentially caller id. The name of the caller is not NECESSARY but it helps you decide if you want to answer the call or not. slugs make a URL look more friendly and makes a user more likely to click it. – Armstrongest Mar 15 '10 at 18:27
  • xian, exactly how is that different from google.com/search?q=cat+puppy ? People who discover URL's will likely do that. I do that. – netrox Jul 17 '10 at 05:25
40

Usability is one reason, if you receive that link in your e-mail, you know what to expect. SEO (search engine optimization) is another reason. Search engines such as google will rank your page higher for the keywords contained in the url

Michiel van Oosterhout
  • 22,190
  • 14
  • 84
  • 123
  • 2
    Why do you think Google made this decision? What motivated it? – Mike Clark Nov 04 '10 at 10:17
  • Can you find any documentation from Google that specifically states they will rank a page higher if the keyword is contained in the url? – chainwork Jul 05 '11 at 20:26
  • @chainwork No, but there's hundreds of signals that a search engine uses to rank pages, and you can be sure that the URL is one such signal. – Michiel van Oosterhout Aug 23 '12 at 18:55
  • 2
    Keywords in the url that match the search are bolded in Google results thus making them stand out more to users conducting the search. – chainwork Oct 16 '12 at 22:18
35

I recently changed my website url format from:

www.mywebsite.com/index.asp?view=display&postid=100

To

www.mywebsite.com/this-is-the-title-of-the-post

and noticed that click through rates to article increased about 300% after the change. It certainly helps the user decide if what they're thinking of clicking on is relevant, in terms of SEO purposes though I have to say I've seen little impact after the change

j0k
  • 21,914
  • 28
  • 75
  • 84
Katy
  • 1,054
  • 7
  • 15
  • 4
    I hope your post titles never, ever change: a lot of people hate dead links and webservices producing them. – Nikita Rybak Sep 04 '10 at 20:44
  • 6
    I can't really guess which CMS or blogging software he's using, but for WordPress and lots of similar ones, modifying the post title after the post has already gone live does not change the slug (and for exactly the reason you mention). – Cyde Weys Feb 21 '12 at 17:04
25

I agree with other responses that any mis-typed slug should 301-redirect to the proper form. In other words, https://stackoverflow.com/questions/47427/wh should redirect to https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls . It has one other benefit that hasn't been mentioned--if you do not do a redirect to a canonical URL, it will appear that you have a near-infinite number of duplicate pages. Google hates duplicate content.

That said, you should really only care about the content ID and allow any input for the slug as long as you redirect. Why?

https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls

... Oops, the mail software cut off the end of the URL! No problem though because you still can roll with just https://stackoverflow.com/questions/47427

The one big problem with this approach is if you derive the slug from the title of your content, how are you going to deal with non-ASCII, UTF-8 titles?

Pang
  • 8,605
  • 144
  • 77
  • 113
Cory R. King
  • 2,678
  • 1
  • 23
  • 21
  • 1
    Nice post, very valid point! +1 As for your question, "how are you going to deal with non-ascii, UTF8 titles?" There are algorithms for this, for example the one WordPress uses. I would post a PHP solution for this exact problem if more than 600 characters were allowed. If you really want to know, post it as a question and I'll be happy to answer it ;) – Mathias Bynens Apr 30 '09 at 13:50
  • 1
    re: "near-infinite number of duplicate pages" - that will only happen if there are links to the non-canon URL. If you keep it consistent within your site there shouldn't be a problem. Your theory about URLs being cut off is kinda silly, the URL could be cut off anywhere, right? Even after 4742, which would lead to a different question. As long as you stick to just standard letters, numbers, dashes and/or underscores in the URL that's less likely to happen. – DisgruntledGoat May 21 '09 at 15:58
  • 2
    As DisgruntledGoat suggested, Google technically wouldn't find any duplicate content unless someone linked to the page with a different slug, therefore tricking google's spider into thinking there is duplicate content. So the spider will hate this page, way to go guys ;) – Austyn Mahoney Jan 12 '10 at 23:49
  • Technically, you need not do a 301 redirect if you embed the rel="canonical" hint in the page. Irrespective of the "near infinite number of duplicate pages", google will take the only valid canonical URL. Amazon doesn't do the 301. Try it: http://www.amazon.com/lat-thinking-stragies/dp/0470942185 However, it's better to do both. Reason is someone can publish the link with a totally modified slug and when the viewer reads it, it looks different from the content -- confusing the viewer. – Ethan Dec 05 '12 at 18:11
  • "how are you going to deal with non-ascii, UTF8 titles?" You percent-encode them. All modern browsers will then actually show the Unicode in all it's multilingual glory in the address bar, but give you an ASCII, percent-encoded URL when you copy to the clipboard. – Stijn de Witt Aug 06 '16 at 20:24
15

It's basically a more meaningful location for the resource. Using the ID is perfectly valid but it means more to machines than people.

Strictly speaking the ID shouldn't be needed if the slug is unique, you can more easily ensure unique slugs by scoping them inside dates.

ie:

/2008/sept/06/why-some-websites-add-slugs-end-of-urls/

Basically this exploits the low likelihood of two identical slugs being in use on the same day. If there is a clash the general convention is to add a counter at the end of the slug but it's rare that you ever see these:

/2008/sept/06/why-some-websites-add-slugs-end-of-urls/
/2008/sept/06/why-some-websites-add-slugs-end-of-urls-1/
/2008/sept/06/why-some-websites-add-slugs-end-of-urls-2/

A lot of slug algorithms also get rid of common words like "the" and "a" to assist in keeping the URL short. This scoped approach also makes it very straightforward to find all resources for a given day, month or year - you simply chop off segments.

Additionally, stackoverflow URLs are bad in the sense that they introduce an additional segment in order to feature the slug, which is a violation of the idea that each segment should represent descending a resource hierarchy.

Andrew Ingram
  • 4,742
  • 2
  • 23
  • 36
15

The reason most sites use it is probably SEO (Search Engine Optimization). Yahoo used to give a reasonable weighting to the presence of the search keyword in the URL itself, and it also helped in the Google result as well.

More recently the search engines have lowered the weighting given to keywords in the URL, likely because the technique is now more common on spam sites than legitimate. Keywords in the URL now have only a very minor impact on the search results, if at all.

As for stackoverflow itself, SEO might be a motivation (old habits die hard) or simply for usability.

DGentry
  • 15,552
  • 7
  • 48
  • 65
11

The term slug comes from the newspaper/publishing business. It's a short title that's used to identify a story in progress. People interested in URL semantics started using a short, abbreviated title in their URLs. It also pays off in SEO land, as keywords in URLs add importance to a page.

Ironically, lots of websites have started place a full serialized-with-hyphens version of the titles in their URLs for strictly SEO purposes, which means the term slug no longer quite applies. This also rankles semantic purists, as many implementations just tack this serialized version of the title at the end of their URLs.

Alan Storm
  • 157,413
  • 86
  • 367
  • 554
10

I note that you can change the text freely. This URL appears to work just as well.

https://stackoverflow.com/questions/47427/why-is-billpg-so-very-awesome

Pang
  • 8,605
  • 144
  • 77
  • 113
billpg
  • 2,923
  • 3
  • 25
  • 53
  • 1
    Is this kind a bug or feature? – Jakub Šturc Sep 10 '08 at 06:27
  • This is most likely a feature. The slug is ignored when server is deciding which question to show. The question is fetched solely based on its id (47427 in this case). – Juha Syrjälä Sep 10 '08 at 19:56
  • 4
    An in fact it makes sure that you can access a post even after the subject has been modified (and thus there is a new URL). – Dirk Vollmar Apr 24 '09 at 07:32
  • 3
    Ideally though, each internet resource ('document') only has 1 URI. So basically, allowing the same document to be viewed through different URIs may have a negative influence on your site in SERP. This is probably the only thing I don't like about Stack Overflow ;) – Mathias Bynens Apr 30 '09 at 11:09
  • 3
    That's why canonical pages exists, and Stack Overflow uses them. =) – Alix Axel Aug 08 '09 at 11:24
  • 4
    @Alix Axel: 301 redirects `>` canonical pages – Mathias Bynens Mar 16 '10 at 14:15
7

As already stated, the 'slug' helps people and the search engines...

Something worth noticing, is that in the source of the page there is a canonical url

This stops the page from being index multiple times.

Example:

<link rel="canonical" href="http://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls">
Robs
  • 8,090
  • 6
  • 36
  • 52
5

Remove the formatting from your question, and you'll see part of the answer:

https://stackoverflow.com/questions/47427/

vs

https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls

With no markup, the second one is self-descriptive.

Pang
  • 8,605
  • 144
  • 77
  • 113
Tom
  • 36,698
  • 31
  • 90
  • 98
3

Don't forget readability when sending a link, not just in search engines. If you email someone the first link they can look at the URL and get a general idea of what it is about. The second one gives no indication of the content of that page before they click.

Chris Bartow
  • 13,713
  • 11
  • 38
  • 45
2

If you emailed someone a link wouldn't it make more sense to include a description by actually writing out a description rather than making the other person parse to the URL where the description exists, and try-to-read-a-bunch-of-hyphenated-words-stuck-together.

Kibbee
  • 62,900
  • 26
  • 139
  • 178
  • You've obviously never been Rick Roll'd, have you. How many links do you receive that are: Check this out. Hilarious! . It would be nice if Youtube did Urls like so: youtube.com/12345/evil-bikini-wax-job-not-work-safe. It would make the links more trustworthy and help me make the decision to click or not. – Armstrongest Mar 15 '10 at 18:42
  • 1
    It would, however, any MVC system I've seen doesn't require the extra evil-bikini-wax-job-not-work-safe part, and could just as easily be sent as youtube.com/12345, and most people who wanted to mail out stuff like that would quickly learn to remove it. – Kibbee Mar 16 '10 at 12:45
2

First off, it's SEO and user friendly, but in the case of the example (this site), it's not done well or correctly (as it is open to black hat tricks and rank poisoning by others, which would reflect badly on this site).

If

https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls

has the content, then

https://stackoverflow.com/questions/47427/

and

https://stackoverflow.com/questions/47427/any-other-bollix

should not be duplicates. They should actually automatically detect the link followed is not using the current text (as obviously the slug is defined by the question title and can be later edited) and they should redirect 301 automatically to

https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls

thus ensuring the "one piece of content to one URI" rule, and if the URI moves/changes, ensure the old bookmarks follow/move with it through 301 redirects (so intelligent browsers can update the bookmarks).

Pang
  • 8,605
  • 144
  • 77
  • 113
Alan Doherty
  • 117
  • 4
  • 1
    View the Page Source and you'll find this: See: here: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html – Armstrongest Mar 15 '10 at 18:37
0

Ideally, the "slug" should be the only identifier needed. In practice, on dynamic sites such as this, you either have to have a unique numerical identifier or start appending/incrementing numbers to the "slug" like Digg does.

double-beep
  • 3,889
  • 12
  • 24
  • 35
Kyle Cronin
  • 72,761
  • 40
  • 144
  • 160
  • 1
    The Digg link was the first one I came across when going down the main page. It's purely coincidental that it also so happens to exemplify how far Digg has fallen - a story about sex addiction has been posted three times. – Kyle Cronin Sep 06 '08 at 16:00