0

The URL for questions on SO have a format like:

https://stackoverflow.com/questions/123456/description-from-title-of-question

which I already know is done using MVC routing, and which I am doing myself.

When you go to the same URL, but without the friendly bit at the end:

https://stackoverflow.com/questions/123456

then StackOverflow adds the friendly bit for you, and you end up with the same address in your browser address bar:

https://stackoverflow.com/questions/123456/description-from-title-of-question

My question is, how does SO do this? Does it involve going to the database, getting the title description and redirecting to the route that includes the title on the end (Creating a new request)? Or is there something in MVC routing which handles this? Or is it being added client side via javascript or something?

I'd also be interested to hear other peoples opinions on good ways of doing this, as well as how SO do it.

Community
  • 1
  • 1
soupy1976
  • 2,787
  • 2
  • 26
  • 34
  • I think this post answers your question http://stackoverflow.com/questions/25259/how-does-stack-overflow-generate-its-seo-friendly-urls – ali Sep 03 '13 at 09:43
  • @user2117295 no it doesn't. That's not what he/she asked for. – Ofer Zelig Sep 03 '13 at 09:45

1 Answers1

1

It's not MVC routing, they get the ID from the URL and redirect (HTTP 302) to the fully qualified SEO-friendly URL. That is, the redirect is done by the server and not using JavaScript.

They use extensive caching, so most of the times they don't fetch the database, but rather an in-memory map table or some 2nd level caching such as Redis.

Read this in-depth overview about StackOverflow's caching: https://meta.stackexchange.com/a/69172

Community
  • 1
  • 1
Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93