Create a gist now

Instantly share code, notes, and snippets.

Basic stub for mod_rewrite-like behaviour using PHP 5.4's development server
// To the extent possible under law, I (Stephan Sokolow) waive all copyright and related or
// neighbouring rights to this code snippet. (Though it'd still be nice if you mention me)
// If we're running under `php -S` with PHP 5.4.0+
if (php_sapi_name() == 'cli-server') {
// Replicate the effects of basic "index.php"-hiding mod_rewrite rules
// Tested working under FatFreeFramework 2.0.6 through 2.0.12.
$_SERVER['SCRIPT_NAME'] = str_replace(__DIR__, '', __FILE__);
// Replicate the FatFree/WordPress/etc. .htaccess "serve existing files" bit
$url_parts = parse_url($_SERVER["REQUEST_URI"]);
$_req = rtrim($_SERVER['DOCUMENT_ROOT'] . $url_parts['path'], '/' . DIRECTORY_SEPARATOR);
if (__FILE__ !== $_req && __DIR__ !== $_req && file_exists($_req)) {
return false; // serve the requested resource as-is.
// TODO: The rest of your index.php goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment