5 April 2013 4 comments Mozilla
People rarely type in long URLs. Therefore it's unlikely that one little typo in that long URL is the the deciding factor whether you get a 200 Found or a 404 Not Found.
However, what people often do is type in a domain name and hit enter. Sometimes they fumble and miss a character or accidentally add an additional one and ultimately land on this error:
Another thing I often do is I type the start of the domain name and fumble with the Awesome Bar and accidentally try to reach just the start of the domain. Like
www.mozill for example.
The browser should in these cases be able to recognize the mistake and offer a nice "Did you mean this domain?" button or something that makes it one click to correct the innocent fumble.
How it could do this would be quite simple. It could record every domain you've visited based on your history. Then it could compute a an Edit distance and if it finds exactly one suggestion, offer it.
Here's how you can use an Edit distance algorithm:
>>> from edit_distance import EditDistance >>> ed = EditDistance(('www.peterbe.com', 'www.mozilla.org', 'news.ycombinator.com', ... 'twitter.com', 'www.facebook.com', 'github.com')) >>> ed.match('www.peterbe.cm') [u'www.peterbe.com'] >>> ed.match('twittter.com') ['twitter.com'] >>> ed.match('www.faecbook.com') ['www.facebook.com'] >>> ed.match('github.comm') ['github.com'] >>> ed.match('neverheardof') 
Here's the implementation I used.
Of course, this functionality should only kick in in the most desperate of cases. Ie. the URL can't resolve to anything. If someone is clever enough to buy the domain name
facebok.com they deserve their traffic. And equally, if you type something like
wwww.peterbe.com I've already set that up redirect to