Created
January 5, 2016 09:59
-
-
Save wadtech/e217714eed2522ef61f2 to your computer and use it in GitHub Desktop.
Simple and generic router file for PHP built-in webserver. Place in your project webroot and run with `php -S localhost:3000 /path/to/router.php`
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 = __DIR__ . DIRECTORY_SEPARATOR . ltrim(parse_url($_SERVER['REQUEST_URI'])['path'], '/'); | |
if (file_exists($path) && !is_dir($path)) { | |
return false; | |
} | |
if (file_exists($path . '/index.php')) { | |
require $path . '/index.php'; | |
} | |
require __DIR__ . '/index.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment