'%s'\n", $from, $to); $redirect[$from] = $to; } } function body_start($title) { global $ARG; switch(strtolower($ARG["STYLE"])) { case "plain": print "
$DEBUG |
The page " . htmlspecialchars($url) . " could not be found.
\n"; body_end(); } if (preg_match('/\.(gif|jpg|png)$/i', $ARG["URI"])) { make404($ARG["URI"]); exit; } foreach($redirect as $srcurl => $dsturl) { $array = array(); if (preg_match("%^".$srcurl."([^?]*)%", $ARG["URI"], $array)) { $path = $array[1]; # if this is an absolute URL, redirect immediately if (preg_match("%^(http|ftp)://%", $dsturl )) { # TODO should honour the delay (later) #redirect the user immediately for now header("Location: $dsturl$path"); exit; } # get apache to map the desturl to a filename $request = @apache_lookup_uri($dsturl.$path); if (!$request) { # lookups of a directory without a trailing slash fail to lookup # this may be a bug in apache 2.2, or it may be a feature # so we work round it (fairly) silently if (isset($DEBUG)) $DEBUG .= sprintf("apache_lookup_uri('%s') FAILED, trying '%s/'\n", $dsturl.$path, $dsturl.$path); $request = @apache_lookup_uri($dsturl.$path."/"); if ($request) $path .= "/"; } if (isset($DEBUG)) { $DEBUG .= sprintf("matched against '%s'\n", $srcurl); $DEBUG .= sprintf("destination is '%s'\n", $dsturl); $DEBUG .= sprintf("new uri is '%s'\n", $request->uri); $DEBUG .= sprintf("new filename is '%s'\n", $request->filename); $DEBUG .= sprintf("content_type is '%s'\n", $request->content_type); } # open_basedir restrictions may prevent us from directly checking # for the existence of the file # so we get a clue from the apache_lookup_uri() result: # if the request would succeed, we'll see a content_type if (isset($request->content_type)) { # debugging if (isset($DEBUG)) $DEBUG.= sprintf("'%s' exists\n", htmlspecialchars($dsturl.$path)); $url = "http://".$ARG["NAME"]; if($ARG["PORT"]!=80) $url .= ":".$ARG["PORT"]; $url .= $dsturl . $path; # if the delay is zero we just redirect if ($ARG["DELAY"] == 0) { header("Location: $url"); exit; } header("HTTP/1.0 200 OK"); # otherwise IE gets upset # otherwise we tell the user what is going on if (!isset($DEBUG)) # do not redirect if debugging header("Refresh: ".$ARG["DELAY"]."; URL=$url"); body_start("Redirecting to new page"); print "\n";
printf("The correct URL is %s
\n",
$url, htmlspecialchars($url));
print "You should be redirected to the correct page within a few seconds
\n";
body_end();
exit();
}
# debugging
if (isset($DEBUG))
{
$DEBUG.= sprintf("'%s' does not exist\n", htmlspecialchars($dsturl.$path));
}
}
else
{
# debugging
if (isset($DEBUG))
$DEBUG.= sprintf("no match against '%s'\n", $srcurl);
}
}
make404($ARG["URI"]);
?>