// 1. Get the original requested URI $requestUri = $_SERVER['REQUEST_URI']; $urlParts = parse_url($requestUri); $path = isset($urlParts['path']) ? $urlParts['path'] : ''; $query = isset($urlParts['query']) ? '?' . $urlParts['query'] : ''; // 2. If uppercase exists, redirect to lowercase version if (preg_match('/[A-Z]/', $path)) { $lowercasePath = strtolower($path); $destination = $lowercasePath . $query; header("Location: " . $destination, true, 301); exit(); } // 3. If lowercase path exists, serve it normally $fullPath = $_SERVER['DOCUMENT_ROOT'] . $path; if (file_exists($fullPath) && !is_dir($fullPath)) { include($fullPath); exit(); } // 4. If lowercase path does NOT exist → URL is dead → return 410 Gone header("HTTP/1.1 410 Gone"); include($_SERVER['DOCUMENT_ROOT'] . '/404.htm'); exit();