Skip to content

Instantly share code, notes, and snippets.

@igregson
Created January 14, 2016 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igregson/38321aaa103590559d65 to your computer and use it in GitHub Desktop.
Save igregson/38321aaa103590559d65 to your computer and use it in GitHub Desktop.
php command-line server fix
<?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