Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$path = parse_url($_SERVER['REQUEST_URI']);
$path = rtrim(ltrim(rtrim($path["path"], '/'), '.'),'/'); //trim trailing slash and prefix dots
$index = realpath(getcwd() .$path ."/index.html");
if (substr($index, 0, strlen(realpath(getcwd()))) === realpath(getcwd()) && file_exists($index)){
try {
readfile($index);
exit;
} catch (Exception $e) {
/*Eating all exceptions*/
readfile($index);
exit;
}
} else {
http_response_code(404);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.