PHP Snippet to Lowercase URL and Redirect
Recently I had to ensure that any URL with an uppercase letter was rewritten. Normally I would do something like this using the .htaccess file and mod_rewrite rules. In order for that to work you have to ensure that the RewriteMap directive is defined in the httpd.conf file, then called from .htaccess. Unfortunately this is a shared server so no access to httpd.conf.
I solved it by adding the following to the beginning of index.php.
if (preg_match('/[A-Z]/', $_SERVER['REQUEST_URI'])) {
$lowercase_file_url = strtolower($_SERVER['REQUEST_URI']);
header('Location: ' . $lowercase_file_url, true, 301);
exit();
}Easy.