Skip to content

Instantly share code, notes, and snippets.

@wadtech
Created January 5, 2016 09:59
Show Gist options
  • Save wadtech/e217714eed2522ef61f2 to your computer and use it in GitHub Desktop.
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`
<?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