tags:

views:

77

answers:

3

I noticed today that SO uses magic URLs in the form. For example, a question is ".../questions/[nnn]/[description]. As an experiment when showing a question I changed the description and hit enter. As expected, it did not affect the request and the question showed just fine, only with a garbage URL:

http://stackoverflow.com/questions/1933822/flksdjfkljlfs

I assume, but could be wrong, that this reflects a RESTful approach to URLs. Since I am in the process of build a new web app, I was wondering, why is this better than than some of the more "traditional" alternatives?

http://stackoverflow.com/questions/1933822
http://stackoverflow.com/questions?Question=1933822

It seems wrong to me, for reasons I can't define, to have a URL with completely redundant and ignored information (the question name).

+6  A: 

It's for SEO (Search Engine Optimization) reasons. Google favors URLs that have in them the text of the search query. It's a bit cheating (that is just my personal opinion) but most websites do it, including mine* :)

The URL for this question is:

http://stackoverflow.com/questions/1934268/whats-the-advantage-of-urls-with-semantically-dead-components

Let's say you search for "urls with semantically dead components". Google uses many factors in deciding the order in which results are shown; but let's say that another site has the same exact factors but an URL like www.site.com/question/1000. Google would display stackoverflow first.


*I go a bit further and 301 (permanently redirect) the most popular search engines that crawl /url/id without /text.

This is done for both the reasons mentioned above and also to have only one valid (canonical) URL for search engines.

If you choose to include extra text in your URLs I suggest you follow the same approach since google somewhat penalizes websites with duplicate content, always have one canonical URL, at least for search engines!

Andreas Bonini
I agree that it's SEO. I disagree that it's cheating - it's giving a hint as to the most important words in the page, effectively.
Jon Skeet
@Jon Skeet, this is done with the `<title>` and `<h[n]>` tags!
Andreas Bonini
While SEO is the primary incentive for this, there's a human factor as well the URLs become a bit more readable.
nos
+1  A: 

I think SO uses a nice approach here. It's a combination of user-friendly and computer-friendly information. The service is able to efficiently locate the correct question because of the ID number, while humans can quickly get an understanding of what the web page is about just by looking at the URL before even clicking on it.

Jeff
+1  A: 

Well with the title as part of the URL, it has meaning when read by humans, too.

Yuliy