2.8.1.8. Redirect to lowercase URL

Here is a code example 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 site's main script, which handles the main part of the requests (usually index.php).

Content

    (1)