(This article is Part 2 in a series about Apache’s loadable modules. The previous topic was mod_ext_filter).
As former Microsoft-ite who made the leap to OSS, one of the things that took a little getting used to with Apache are that filenames are case-sensitive. While that’s long since been hammered into my soul, a great many other people browsing the web aren’t aware that some webservers are case-senstive, while others are not. Sometimes I’ll see “http://www.example.com/signup” in my access logs when what the person really wanted is “http://www.example.com/Signup”. I could easily catch these simple typos with a mod_rewrite rule, but what if the user entered “http://www.example.com/Sign-up” or “http://www.example.com/Signpu”? Trying to plan for the ways a URL could be miscontrued would be make for a lot of ugly mod_rewrite rules. A better choice is to load Apache’s mod_speling module.
Mod_speling is very easy to implement. And what’s more, unlike mod_ext_filter, it can be used from within an .htaccess file–shared hosting users rejoice! The module is normally loaded by default (though spell-checking is disabled), but you might want to double-check Apache’s http.conf:
LoadModule speling_module modules/mod_speling.so
Enabling mod_speling is as easy as:
A couple of points to remember:
- mod_speling will only catch and correct up to one URL misspelling at a time. For true fuzzy matching you’ll have to use a more advanced solution.
- If Apache finds several likely matching URLs, the user will be presented with a list to pick from.
- Renaming files and not updating links, relying upon mod_speling to automagically fix them, isn’t a great idea. The module does a directory scan each time it intercepts a 404. If you have a lot misspelled files and a lot of pageviews, you will experience a noticable performance degradation.
For more information, check out the official Apache docs.