Thursday, July 28, 2005

Case sensitivity of redirects

Today's beauty of a problem was the issue of case sensitivity in URL redirects under Apache. The problem is that the case insensitivity of the URL's on our Mac XServe has spoiled our users into expecting case insensitivity in all URL issues on our servers.

Unfortunately, redirects are case sensitive. Obviously, this is to keep server load down, since the server must chew through the list of redirects for every file request. When you have to do regular expression pattern matching on a list of patterns for every request before anything else happens, you don't want the added overhead of checking every letter against its upper case, lower case, accented, umlauted, etc. counterpart. That's many times the CPU cycles than a simple case-sensitive string comparison.

So an email goes out today with an uppercase character in the URL. Normally, not a problem, but it was done in a URL that is being redirected (they wanted a short URL that has one word instead of two words after the domain name), and they didn't check the URL before sending it out. Result: broken link.

One option would be to add another redirect with the offending case-sensitive spelling, but this would incur a server performance penalty on every single request from now on. Sending out a correction is apparently not an option, and I was getting threats of going over my head to the department head.

But I found a cool solution. In the 404 page, just drop in some Javascript to detect a URL with an uppercase character in it, and if one is detected, correct it, and either redirect immediately or offer a link. Simple, and only incurs a server hit when someone actually gets a broken link. Even better, it handles all case sensitivity problems that may occur in the future. Gotta love nice, simple solutions that defuse nasty problems.

No comments: