Convert to lowercase in a mod_rewrite rule Convert to lowercase in a mod_rewrite rule apache apache

Convert to lowercase in a mod_rewrite rule


First, put the following line in the <VirtualHost> section of your .conf file.(For me that lives at /etc/httpd/vhosts.d/00foo.conf.)

RewriteMap lc int:tolower 

You can replace lc with any name you want.Then restart apache, which you can do with sudo service httpd restart.

Finally, add this in your .htaccess file:

RewriteRule ^/(.*)$ /${lc:$1} 


RewriteMap tolower int:tolowerRewriteRule  ^([^/]+)/?$  somedir/${tolower:$1}


I would make it a 301 redirect, NOT a URL rewrite, for SEO purposes:

RewriteMap tolower int:tolowerRewriteRule  ^([^/]+)/?$  somedir/${tolower:$1} [R=301,L]