Created
February 1, 2021 17:05
-
-
Save rotexdegba/82df49f631e7e15b50fa013cdb7d288a to your computer and use it in GitHub Desktop.
Router script for the builtin PHP webserver to handle urls ending in dot something
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 | |
// This script is intended to fix the php built-in server issue with urls that | |
// contain a .something at the end. The built-in server tries to always treat | |
// such urls as static assets when sometimes they are routes meant to be | |
// forwarded to the index.php. See below for more info: | |
// | |
// https://bugs.php.net/bug.php?id=61286 | |
// https://github.com/slimphp/Slim/issues/359 | |
// https://gonzalo123.com/2012/10/15/how-to-rewrite-urls-with-php-5-4s-built-in-web-server/ | |
// https://gist.github.com/aenglander/8e2f83c4526fccdcdead | |
// | |
$ds = DIRECTORY_SEPARATOR; | |
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | |
$path = str_replace(["\\", '/'], [$ds, $ds], $path); // make path use OS directory separator | |
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $path)) { | |
return false; | |
} else { | |
$_SERVER['SCRIPT_NAME'] = '/index.php'; | |
require $_SERVER['DOCUMENT_ROOT'] . "{$ds}index.php"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment