Created
May 19, 2016 14:41
-
-
Save andregoncalves/df0cce91cdfff7394c04f0c3be15d2f3 to your computer and use it in GitHub Desktop.
.htaccess like router file for php dev web server
This file contains hidden or 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 | |
| // php -S localhost:3000 router.php | |
| $root = $_SERVER['DOCUMENT_ROOT']; | |
| chdir($root); | |
| $path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/'); | |
| set_include_path(get_include_path().':'.__DIR__); | |
| if(file_exists($root.$path)) | |
| { | |
| if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/') | |
| $path = rtrim($path,'/').'/index.php'; | |
| if(strpos($path,'.php') === false) return false; | |
| else { | |
| chdir(dirname($root.$path)); | |
| require_once $root.$path; | |
| } | |
| } | |
| elseif (file_exists($root.'/public'.$path)) { | |
| $array = explode('.', $path); | |
| $extension = end($array); | |
| if ($extension == 'css') header('Content-Type: text/css'); | |
| require_once $root.'/public'.$path; | |
| } | |
| else include_once 'index.php'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment