Apache: Convert uppercase to lowercase

Friday, March 13 2009 @ 04:19 PM CST

Contributed by: nat

We had a requirement from a client whose windows website we were migrating to UNIX that the new site be able to handle mixed case tickers, ie, /pwc, /Pwc, /PWC, /pwC, etc. Using mod_rewrite, it was doable:

    # Take any mixed or uppercase ticker and set to lower
    RewriteMap    lowercase    int:tolower
    RewriteRule ^(/[A-Z]...?)$ $ [R,L]
    RewriteRule ^(/.[A-Z]..?)$ $ [R,L]
    RewriteRule ^(/..[A-Z].?)$ $ [R,L]
    RewriteRule ^(/...[A-Z])$ $ [R,L]
This case conversion will be true for any 3 or 4 char URI with an uppercase letter. (It would probably be better to replace the "." above with [a-zA-Z], as it's likely intended for only chars to replace. Above will transform /a/BB as well, which is probably not desired.)

0 comments



/article.php/200903131619559