Improve automatic redirections
This commit is contained in:
+59
-23
@@ -42,38 +42,74 @@ STR;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect the user according to found information
|
{ // Try and redirect user according to the full provided URI
|
||||||
$name = urldecode($_SERVER['REQUEST_URI']);
|
$url = urldecode($_SERVER['REQUEST_URI']);
|
||||||
$STATEMENTS['LookUp']->bind_param('s', $name);
|
$url_parts = parse_url($url);
|
||||||
if(!$STATEMENTS['LookUp']->execute()) {
|
|
||||||
header("Service Unavailable", true, 503);
|
|
||||||
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
// Try and identify a redirect by the full URI.
|
||||||
$res = $STATEMENTS['LookUp']->get_result();
|
$STATEMENTS['LookUp']->bind_param('s', $url);
|
||||||
if ($res->num_rows == 0) {
|
if (!$STATEMENTS['LookUp']->execute()) {
|
||||||
// Insert the undiscovered URL into the redirect database.
|
|
||||||
$STATEMENTS['Insert']->bind_param('s', $name);
|
|
||||||
if (!$STATEMENTS['Insert']->execute()) {
|
|
||||||
header("Service Unavailable", true, 503);
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
} else {
|
} else {
|
||||||
if (!$STATEMENTS['Insert']->get_result()) {
|
$res = $STATEMENTS['LookUp']->get_result();
|
||||||
header("Service Unavailable", true, 503);
|
if ($res->num_rows != 0) {
|
||||||
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header("Location: https://www.xaymar.com/404.html");
|
|
||||||
} else {
|
|
||||||
while($obj = $res->fetch_object()) {
|
while($obj = $res->fetch_object()) {
|
||||||
if ($obj->target != null) {
|
if ($obj->target != null) {
|
||||||
header("Location: ".$obj->target, true, 307);
|
header("Location: ".$obj->target, true, 307);
|
||||||
|
$res->close();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$STATEMENTS['Insert']->bind_param('s', $url);
|
||||||
|
if (!$STATEMENTS['Insert']->execute()) {
|
||||||
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
|
} else if (!$STATEMENTS['Insert']->get_result()) {
|
||||||
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try and identify a redirect by the path.
|
||||||
|
$STATEMENTS['LookUp']->bind_param('s', $url_parts->path);
|
||||||
|
if (!$STATEMENTS['LookUp']->execute()) {
|
||||||
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
|
} else {
|
||||||
|
$res = $STATEMENTS['LookUp']->get_result();
|
||||||
|
if ($res->num_rows != 0) {
|
||||||
|
while($obj = $res->fetch_object()) {
|
||||||
|
if ($obj->target != null) {
|
||||||
|
header("Location: ".$obj->target, true, 307);
|
||||||
|
$res->close();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$STATEMENTS['Insert']->bind_param('s', $url_parts->path);
|
||||||
|
if (!$STATEMENTS['Insert']->execute()) {
|
||||||
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
|
} else if (!$STATEMENTS['Insert']->get_result()) {
|
||||||
|
header("Service Unavailable", true, 503);
|
||||||
|
header("Retry-After: 30", true);
|
||||||
|
die($SQL['Handle']->errno." ".$SQL['Handle']->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// In all other cases, just redirect to 404.
|
||||||
header("Location: https://www.xaymar.com/404.html");
|
header("Location: https://www.xaymar.com/404.html");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$res->close();
|
|
||||||
|
|
||||||
die();
|
die();
|
||||||
Reference in New Issue
Block a user