Jump to main navigation


mod_rewrite changes url to lower-case in Windows

090328

Using mod_rewrite to ensure canonical URL's in my CMS, I run across a strange behavior (bug?) of mod_rewrite. It seems that in Windows and under certain circumstances, it changes the case of the URL to lowercase. While this normally won't be a problem (Windows URL's are case insensitive) it can have undesirable effects if you need process the URL with PHP, for example.

Here's the code:

RewriteEngine On
RewriteBase /

# Add trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]

With this rewrite rule, a url such as /someFolder/page gets rewritten as /somefolder/page/ (note the lowercase 'f' in somefolder).

Now if I want to process the URL with PHP, and I look for "someFolder", I won't find it unless I use a case insensitive search, which might or not be possible.

I couldn't find much info about this issue on the internet, but in a forum (which I can't find anymore) I read that mod_rewrite changes the case of the URL for efficiency purposes when comparing strings. Which seems like a safe thing to do but it turns out to be problematic in some cases.

I suppose this won't happen in Linux (I'd like to test it some time), so it's only a problem while I develop on Windows, which is one more reason to start thinking of switching to Linux soon... :)

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments to “mod_rewrite changes url to lower-case in Windows”

Comments are closed.

Additional content and navigation

Categories

Recent comments