I am developing a web site using ASP.NET MVC. The site will be similar to StackOverflow in that there will be user submitted items that will have a numeric id and a textual title.
Now I am thinking how to design the URL routing system for the “item details” pages. I had thought of using the id alone (as in http://www.mysite.com/items/1234) or the title alone (as in http://www.mysite.com/items/how-to-foobarize-a-fizzbuzz). I see however that StackOverflow uses instead both of them (as in http://www.mysite.com/items/1234/how-to-foobarize-a-fizzbuzz).
So which one is the best approach? And what is the point of using both the id and the title in the URL? Isn’t this redundant?
The advantage of using the title in that form (usually referred to as a “slug”) is basically just that of URL readability. However, if you are not enforcing a uniqueness constraint on your titles then this will not necessarily be adequate to identify a record. Therefore, when both are used, the ID can be there for the server to actually to do the lookup and the slug is there for humans to read.