Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OriPekelman/fff5a5e8a43309943879 to your computer and use it in GitHub Desktop.
Save OriPekelman/fff5a5e8a43309943879 to your computer and use it in GitHub Desktop.
<?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