From 70ec2caa93435f2abaa75b8b9c47065268764741 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 8 Feb 2019 20:53:49 -0700 Subject: [PATCH] Set cache-control on thumbnails --- cache/.htaccess | 6 ++++++ cache/handle_404.php | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cache/.htaccess b/cache/.htaccess index 9603d64..f6040fe 100644 --- a/cache/.htaccess +++ b/cache/.htaccess @@ -9,3 +9,9 @@ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)/?$ handle_404.php?file=$1 [QSA,L] + + + + Header set Cache-Control "max-age=604800, public" + + \ No newline at end of file diff --git a/cache/handle_404.php b/cache/handle_404.php index 0181921..571cded 100644 --- a/cache/handle_404.php +++ b/cache/handle_404.php @@ -9,6 +9,7 @@ require_once __DIR__ . "/../required.php"; header("Content-Type: text/plain;utf-8"); +header("Cache-Control: max-age=" . (60 * 60 * 24 * 7)); $urlparts = explode("/", $_GET['file']); $fileparts = explode(".", end($urlparts)); @@ -24,9 +25,8 @@ if (!preg_match("/^[A-Za-z0-9\-!_]+$/", $fileparts[0])) { } if (strpos($fileparts[0], "SHA1_") === 0) { - $hash = str_replace("SHA1_", "", $fileparts[0]); - if ($database->has("imagecache", ["hash" => $hash])) { - $url = $database->get("imagecache", 'url', ["hash" => $hash]); + if ($database->has("imagecache", ["hash" => $fileparts[0]])) { + $url = $database->get("imagecache", 'url', ["hash" => $fileparts[0]]); echo $url; } else { http_response_code(404);