From 9f6bf3fd40f4df47cb7f182f6b67255ef155f76d Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 24 Jun 2024 16:38:33 +0900 Subject: [PATCH] fix: move rewrite.php to system/rewrite.php To avoid `CodeIgniter\CLI\Commands->discoverCommands()` loads `rewrite.php`. FileLocator::findQualifiedNameFromPath() tries to generate classname from the path, and calls class_exists(), then it loads `rewrite.php`. If PHP_SAPI is `apache2handler`, it will be executed. --- system/Commands/Server/Serve.php | 2 +- system/{Commands/Server => }/rewrite.php | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) rename system/{Commands/Server => }/rewrite.php (93%) diff --git a/system/Commands/Server/Serve.php b/system/Commands/Server/Serve.php index c32cd6560ab2..82e58998a732 100644 --- a/system/Commands/Server/Serve.php +++ b/system/Commands/Server/Serve.php @@ -103,7 +103,7 @@ public function run(array $params) $docroot = escapeshellarg(FCPATH); // Mimic Apache's mod_rewrite functionality with user settings. - $rewrite = escapeshellarg(__DIR__ . '/rewrite.php'); + $rewrite = escapeshellarg(SYSTEMPATH . 'rewrite.php'); // Call PHP's built-in webserver, making sure to set our // base path to the public folder, and to use the rewrite file diff --git a/system/Commands/Server/rewrite.php b/system/rewrite.php similarity index 93% rename from system/Commands/Server/rewrite.php rename to system/rewrite.php index f936cd63f0b0..aba4560446fc 100644 --- a/system/Commands/Server/rewrite.php +++ b/system/rewrite.php @@ -21,11 +21,6 @@ */ // @codeCoverageIgnoreStart -// Avoid this file run when listing commands -if (PHP_SAPI === 'cli') { - return; -} - $uri = urldecode( parse_url('https://codeigniter.com' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? '' );