Created
January 14, 2016 22:38
-
-
Save igregson/38321aaa103590559d65 to your computer and use it in GitHub Desktop.
php command-line server fix
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 | |
// The Story: | |
// | |
// PHP's cli server (`php -S localhost:7777`) treats dots (`.`) in paths | |
// as a stataic file request... | |
// Many seem to consider this a bug, except the PHP-powers-that-be | |
// see: https://bugs.php.net/bug.php?id=61286 | |
// So... | |
// Turns out there's a workaround | |
// complements of the Drupal folks | |
// https://www.drupal.org/node/1543858 | |
// https://github.com/elifesciences/isolated-drupal-behat-extension/blob/master/features/bootstrap/.ht.router.php | |
// | |
// The php cli sever allows for specifying config files. | |
// So, run | |
// > php -S localhost:7777 php-cli-server-fix.php | |
// | |
// Smile :) | |
$url = parse_url($_SERVER["REQUEST_URI"]); | |
if (file_exists('.' . $url['path'])) { | |
// Serve the requested resource as-is. | |
return false; | |
} | |
// Populate the "q" query key with the path, skip the leading slash. | |
$_GET['q'] = $_REQUEST['q'] = ltrim($url['path'], '/'); | |
// Run | |
require 'index.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment