2.8.1.8. Redirect to URL in lower case

Example code that performs a 301 redirect to a lowercase URL if the original URL contains at least one uppercase character:

if ($_SERVER['REQUEST_URI'] != strtolower($_SERVER['REQUEST_URI'])) {
    header('Location: //' .  $_SERVER['HTTP_HOST'] . strtolower($_SERVER['REQUEST_URI']), true, 301);
    exit();
}

This code should be placed at the beginning of the main script of the site, which receives the bulk of requests (usually index.php).

Content