Forcing Lower-Case URLs In Apache

I’ve been working on a few tweaks to Catallaxy Services and one of the things I wanted to update was URLs.  In the UNIX world, URLs are be case-sensitive, so /Page1.html is totally different from /page1.html.  In my case, I had some presentations which had capital letters, but a person typing might enter lower-case letters and get a 404 page.

Wanting to avoid that, I started looking for ways to get around this dilemma.  A Chris Abernethy blog post on the topic solved the problem for me. What follows is the segment to add to your httpd.conf file, after making sure that you have

# ... other modules loaded
LoadModule rewrite_module    modules/

# ... other settings
RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

Doing this will automatically re-route any incoming URLs to their lower-case form. Then, you just have to make sure that all of your pages serve content based on lower-cased URLs. So this means that you can serve the same page regardless of whether a person types in “oltp” or “OLTP” in the URL.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s