开发者

How do SO URLs self correct themselves if they are mistyped?

If an extra character (like a period, comma or a brack开发者_JAVA技巧et or even alphabets) gets accidentally added to URL on the stackoverflow.com domain, a 404 error page is not thrown. Instead, URLs self correct themselves & the user is led to the relevant webpage.

For instance, the extra 4 letters I added to the end of a valid SO URL to demonstrate this would be automatically removed when you access the below URL - https://stackoverflow.com/questions/194812/list-of-freely-available-programming-booksasdf

I guess this has something to do with ASP.NET MVC Routing. How is this feature implemented?


Well, this is quite simple to explain I guess, even without knowing the code behind it: The text is just candy for search engines and people reading the URL:

This URL will work as well, with the complete text removed!

The only part really important is the question ID that's also embedded in the "path".


This is because EVERYTHING after http://stackoverflow.com/questions/194812 is ignored. It is just there to make the link, if posted somewhere, if more speaking.

Internally the URL is mapped to a handler, e.g., by a rewrite, that transforms into something like: http://stackoverflow.com/questions.php?id=194812 (just an example, don't know the correct internal URL)

This also makes the URL search engine friendly, besides being more readable to humans.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜