404 Not Found

Cannot find $_SERVER[REQUEST_URI].

EOT; exit (); // FUNCTIONS ================================================================================== function checkForRedirectPath() { // Check to see if we can perform redirect // Return redirect path relative to the site root, with a leading slash // Must start from site root chdir ($_SERVER['DOCUMENT_ROOT']); // Separate out the query string if there is one, and preserve it for later $URLparts = explode('?', $_SERVER['REQUEST_URI']); if ($URLparts[1]) $URLparts[1] = '?' . $URLparts[1]; // Turn the request URI into an array. Because leading and trailing slashes upset explode // (they create empty array values) do some ugly hacks to stop that from happening. $startDirArr = explode("/", substr(urldecode($URLparts[0]), 1)); $arrLen = count($startDirArr) - 1; if ($startDirArr[$arrLen] == "") unset ($startDirArr[$arrLen]); // Perform the check if (($caseCheck = findInDirCase("", $startDirArr)) !== FALSE) { // Match found; // Make sure it's properly encoded $caseCheck = str_replace('%2F', '/', rawurlencode($caseCheck)); return '/' . $caseCheck . $URLparts[1]; } else { // Nothing found return ""; } } function findInDirCase ($pStartPath, $pRemainderArr) { // Attempt a case-insensitive match of the path $pRemainderArr in the local directory // $pStartPath. Set $pStartPath to "" to search starting from the current working directory. // The target (needle) path $pRemainderArr is an array instead of a string; initially it // comprises the target path split into an array (with no empty entries!) Each time a match is // made (in heaven) the first element is docked and the remaining elements are passed back // to the function recursively to continue the search. Hence the weird name. // Set glob path; need a slash before the * if pStartPath != "" $globPath = $pStartPath ? "$pStartPath/" : ""; // First do a case-sensitive check if (!file_exists($pathCheck = $globPath . $pRemainderArr[0])) { // Not found by case-sensitive match, try case insensitive // Retrieve all files in the start path. $checkArr = glob("$globPath*"); // Check to see if the next item (0) in the search path array pRemainderArr exists // pathCheck will contain FALSE for no match, or the current match so far including path $pathCheck = inArrayCaseFix($globPath . $pRemainderArr[0], $checkArr); } if ($pathCheck !== FALSE) { // Match found // Drop current (0) item as we've found it $localRemainderArr = $pRemainderArr; unset ($localRemainderArr[0]); if (count($localRemainderArr) == 0) { // No more path elements; we're done // Because of the way glob works, $pathCheck itself contains the full path of the progress // made so far. We can therefore return this as our result variable. With an added '/' if // it is a directory if (is_dir($pathCheck)) $pathCheck .= "/"; // give it its trailing slash! return $pathCheck; // found our destination } else { // We have one or more items left in remainderArr $localRemainderArr = array_values($localRemainderArr); // redo the array keys if (!is_dir($pathCheck)) { // The current path element is not a directory, we cannot proceed here // If we need paths of the form /dir/script/arg, then replace this line with // return $pathCheck . '/' . implode($localRemainderArr, '/'); return FALSE; } else { // We have another directory level to explore; recurse return findInDirCase($pathCheck, $localRemainderArr); } } } else { // No match found for this path element; return FALSE; } } function inArrayCaseFix ($pTarget, $pArray) { // Case-insensitive version of in_array, which returns the case-corrected result // or FALSE if nothing was found. Assumes a string needle $pTarget and an array // haystack $pArray. Performs a basic linear search; $pArray does not need to be sorted. // Inspired by code posted to PHP.net by one_eddie (at tenbit.pl) // Repurposed by me to return the case-corrected item foreach ($pArray as $currItem) if (strtoupper($pTarget) == strtoupper($currItem)) return $currItem; return FALSE; // nothing found } ?>