Created
July 6, 2012 03:39
-
-
Save ssokolow/3057918 to your computer and use it in GitHub Desktop.
Basic stub for mod_rewrite-like behaviour using PHP 5.4's development server
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 | |
// 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__); | |
$_SERVER['SCRIPT_FILENAME'] = __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