From a2e6a54a311bdc9fba52f028d2ea41a653491f8a Mon Sep 17 00:00:00 2001 From: Parabola Date: Thu, 24 Jul 2014 02:36:24 +0000 Subject: handle 404, and serving itself correctly --- index.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.php b/index.php index 95a8af1..72c7333 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,25 @@ $root = $_SERVER["DOCUMENT_ROOT"]; //$root = "/srv/http/repo/public/main"; $dirname = explode("?", $_SERVER["REQUEST_URI"], 2)[0]; +if (!is_dir($root.'/'.$dirname)) { + if (is_file($root.'/'.$dirname)) { + header('Content-Type: text/plain'); // gross, but if Nginx is "properly" configured, this only happens when serving itself, which is text + readfile($root.'/'.$dirname); + } else { + header("HTTP/1.0 404 Not Found"); + // This is the template used by Nginx internally; if you want something else, have Nginx intercept it. Separation of concerns. + ?> +404 Not Found + +

404 Not Found

+
+ + +