0) { if (is_dir($path.$dir)) { $path.=$dir.'/'; $absolute.=$dir.'/'; } else break; } $path.='404.txt'; //Search in the 404.txt file for the first matching for $oldPath $newPath=''; $httpStatus=302; $found=false; if (is_file($path)&&($handle=@fopen($path,'r'))) { while (!feof($handle)) { $line=trim(fgets($handle,4096)); if ((strlen($line)<3)||($line[0]=='#')) continue; //comment or invalid $map=preg_split('"\s+"',$line,4); if (count($map)<2) continue; //invalid $mapOld=$map[1]; if ($mapOld[0]!='/') $mapOld=$absolute.$mapOld; if (@preg_match('"^'.$mapOld.'$"iD',$oldPath)&& ((($status=$map[0])==='gone')|| ((count($map)>2)&& (strlen($newPath=@preg_replace('"^'.$mapOld.'$"iD',$map[2],$oldPath))>0)))) { $found=true; switch ($status) { case 'permanent': $httpStatus=301; break; case 'found': case 'temp': $httpStatus=302; break; case 'seeother': $httpStatus=303; break; case 'temporary': $httpStatus=307; break; case 'gone': $httpStatus=410; break; default: $found=false; } if ($found&&(strlen($newPath)>0)) { if (!preg_match('"^(?:(?:[a-z]{3,6}:)|(?:\.\./))"i',$newPath)) //No URI Scheme, and no ../ in front {//When it is possible and not already the case, make the redirection an absolute URL if (empty($defaultNewServer)&&isset($_SERVER['HTTP_HOST'])) { $defaultNewServer='http://'.$_SERVER['HTTP_HOST']; if (isset($_SERVER['SERVER_PORT'])&&($_SERVER['SERVER_PORT']!='80')) $defaultNewServer.=':'.$_SERVER['SERVER_PORT']; if ($newPath[0]!=='/') //relative address $newPath=rtrim(substr($oldPath,-1,1)==='/' ? $oldPath : dirname($oldPath),'/\\').'/'.$newPath; } $newPath=$defaultNewServer.$newPath; } break; } } } fclose($handle); } if ($found) //Redirect if new address is found { if ($httpStatus===410) { header('HTTP/1.1 410 Gone'); header('Status: 410 Gone'); echo ''."\n", ''."\n", '
'."\n", ''."\n", ''."\n", empty($customRedirect) ? '' : ''."\n", 'The requested resource '.$oldPath.' is no longer available on this server and there is no forwarding address. ', 'Please remove all references to this resource.
'."\n", ''."\n", ''."\n"; } else { if (isset($oldUrlParsed['query'])) $newPath.='?'.$oldUrlParsed['query']; $status=array(301=>'Moved Permanently',302=>'Found',303=>'See Other',307=>'Temporary Redirect'); header('Location: '.$newPath); header('HTTP/1.1 '.$httpStatus.' '.$status[$httpStatus]); header('Status: '.$httpStatus.' '.$status[$httpStatus]); echo ''."\n", ''."\n", ''."\n", ''."\n", ''."\n", ''."\n", 'The document has moved here.
'."\n", ''."\n", ''."\n"; } } else //404 error message { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); echo ''."\n", ''."\n", ''."\n", ''."\n", ''."\n", empty($customRedirect) ? '' : ''."\n", 'The requested URL '.$oldPath.' was not found on this server.
'."\n", ''."\n", ''."\n"; } ?>