commit d522d67d7087ed69a9c0076da714d7ed26343c17
parent dc7be5ad927b08e4930ae459e0f27114ba84d3fc
Author: Florian <flokX@users.noreply.github.com>
Date: Mon, 4 Feb 2019 14:33:01 +0100
Update redirect.php
Don't count .map file requests as 404
Consistent variable naming
Diffstat:
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/redirect.php b/redirect.php
@@ -3,6 +3,7 @@
// All relevant changes can be made in the data file. Please read the docs: https://github.com/flokX/devShort/wiki
$short = htmlspecialchars($_GET["short"]);
+$return_404 = array("favicon.ico", "assets/vendor/bootstrap/bootstrap.min.css.map", "assets/vendor/frappe-charts/frappe-charts.min.iife.js.map");
// If the robots.txt is requested, return it
if ($short === "robots.txt") {
@@ -10,7 +11,7 @@ if ($short === "robots.txt") {
echo "User-agent: *\n";
echo "Disallow: /\n";
exit;
-} else if ($short === "favicon.ico") {
+} else if (in_array($short, $return_404)) {
header("HTTP/1.1 404 Not Found");
exit;
}
@@ -24,10 +25,10 @@ function count_access($base_path, $name) {
}
$base_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "admin"));
-$data = json_decode(file_get_contents($base_path . DIRECTORY_SEPARATOR . "config.json"), true);
+$config_content = json_decode(file_get_contents($base_path . DIRECTORY_SEPARATOR . "config.json"), true);
-if (array_key_exists($short, $data["shortlinks"])) {
- header("Location: " . $data["shortlinks"][$short], $http_response_code=303);
+if (array_key_exists($short, $config_content["shortlinks"])) {
+ header("Location: " . $config_content["shortlinks"][$short], $http_response_code=303);
count_access($base_path, $short);
exit;
} else {
@@ -36,8 +37,8 @@ if (array_key_exists($short, $data["shortlinks"])) {
// Generator for page customization
$links_string = "";
- if ($data["settings"]["custom_links"]) {
- foreach ($data["settings"]["custom_links"] as $name => $url) {
+ if ($config_content["settings"]["custom_links"]) {
+ foreach ($config_content["settings"]["custom_links"] as $name => $url) {
$links_string = $links_string . "<a href=\"$url\" class=\"badge badge-secondary\">$name</a> ";
}
$links_string = substr($links_string, 0, -1);
@@ -53,9 +54,9 @@ if (array_key_exists($short, $data["shortlinks"])) {
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="noindex, nofollow">
- <meta name="author" content="<?php echo $data["settings"]["author"]; ?> and the devShort team">
- <link rel="icon" href="<?php echo $data["settings"]["favicon"]; ?>">
- <title>404 | <?php echo $data["settings"]["name"]; ?></title>
+ <meta name="author" content="<?php echo $config_content["settings"]["author"]; ?> and the devShort team">
+ <link rel="icon" href="<?php echo $config_content["settings"]["favicon"]; ?>">
+ <title>404 | <?php echo $config_content["settings"]["name"]; ?></title>
<link href="assets/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="assets/main.css" rel="stylesheet">
</head>
@@ -66,8 +67,8 @@ if (array_key_exists($short, $data["shortlinks"])) {
<div class="container">
<nav class="mt-3" aria-label="breadcrumb">
<ol class="breadcrumb">
- <li class="breadcrumb-item"><a href="<?php echo $data["settings"]["home_link"]; ?>">Home</a></li>
- <li class="breadcrumb-item"><?php echo $data["settings"]["name"]; ?></li>
+ <li class="breadcrumb-item"><a href="<?php echo $config_content["settings"]["home_link"]; ?>">Home</a></li>
+ <li class="breadcrumb-item"><?php echo $config_content["settings"]["name"]; ?></li>
<li class="breadcrumb-item active" aria-current="page">404</li>
</ol>
</nav>
@@ -79,7 +80,7 @@ if (array_key_exists($short, $data["shortlinks"])) {
<footer class="footer mt-auto py-3">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
- <span class="text-muted">© <?php echo date("Y") . " " . $data["settings"]["author"]; ?> and <a href="https://github.com/flokX/devShort">devShort</a></span>
+ <span class="text-muted">© <?php echo date("Y") . " " . $config_content["settings"]["author"]; ?> and <a href="https://github.com/flokX/devShort">devShort</a></span>
<?php if ($links_string) { echo "<span class=\"text-muted\">$links_string</span>"; } ?>
</div>
</div>