Apache: Convert uppercase to lowercase

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]...?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/.[A-Z]..?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/..[A-Z].?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/...[A-Z])$ ${lowercase:$1} [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.)

Share and Enjoy:
  • Print
  • Facebook
  • Twitter
  • PDF

One Reply to “Apache: Convert uppercase to lowercase”

  1. Note that this gets easier if the target is a different path, ie: redirect /pcef or /PCEF or /PceF etc to /some/other/page/pcef. To do so, simply use mod_rewrite with the NC option:

    RewriteRule ^/pcef /some/other/page/pcef [NC,R,L]

Leave a Reply

Your email address will not be published. Required fields are marked *