diff options
-rw-r--r-- | index.php | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -19,6 +19,20 @@ $dirname = explode("?", $_SERVER["REQUEST_URI"], 2)[0]; //////////////////////////////////////////////////////////////////////////////// +function show_404() { + // This is the template used by Nginx internally; + // if you want something else, have Nginx intercept it. + // Separation of concerns. + ?><html> +<head><title>404 Not Found</title></head> +<body bgcolor="white"> +<center><h1>404 Not Found</h1></center> +<hr><center><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></center> +</body> +</html> +<?php +} + function normalizeN($filename) { $parts = preg_split("|/+|", $filename, -1, PREG_SPLIT_NO_EMPTY); $abs = substr($filename, 0, 1) === '/'; @@ -76,6 +90,19 @@ function classify($root, $dirname, $filename) { } //////////////////////////////////////////////////////////////////////////////// + +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"); + show_404(); + } + exit(0); +} + +//////////////////////////////////////////////////////////////////////////////// ?> <!DOCTYPE html> <html lang="en"> |