Created
May 18, 2015 11:49
-
-
Save OriPekelman/fff5a5e8a43309943879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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