Last active
August 2, 2024 16:42
-
-
Save rosswintle/f516820849ad0a883151e398645df423 to your computer and use it in GitHub Desktop.
PHP web server router for WordPress
This file contains hidden or 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 | |
/** | |
* A PHP appliction router for WordPress. Can be used with command line PHP to run WordPress: | |
* | |
* php -S localhost:8000 ./router.php | |
* | |
* This is a minimal version of the router from WP-CLI's "server" command. | |
*/ | |
define('ABSPATH', __DIR__ . '/'); | |
if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js|webp|aiff)$/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { | |
return false; // serve the requested resource as-is. | |
} elseif (preg_match('/\.php$/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { | |
require ABSPATH . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | |
} elseif (file_exists(ABSPATH . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . 'index.php')) { | |
require(ABSPATH . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . 'index.php'); | |
} else { | |
require 'index.php'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment