Fix router to properly set $_SERVER variables for entry points and pretty permalinks#89
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plan: Support pretty permalinks and multiple WordPress entry points
Problem
The current router.php doesn't properly set
$_SERVERvariables when routing requests to PHP files. This causes issues with:wp-login.phpand other entry pointsRoot Cause
When the router requires a PHP file (like
wp-login.phporindex.php), the$_SERVERvariables still reflect the router script, not the actual PHP file being executed. WordPress relies on these variables to determine the current URL and script.Solution Plan
$_SERVERvariable handling in router.phpSCRIPT_NAMEto the correct PHP file being executedPHP_SELFto matchSCRIPT_NAMESCRIPT_FILENAMEto the full path of the PHP filestrpos)Changes Made
1. router.php
Improved PHP file detection:
strpos($wpcli_server_path, '.php')withpathinfo($wpcli_server_path, PATHINFO_EXTENSION) === 'php'.php(e.g.,/my.php-files/image.jpg)Fixed $_SERVER variables for PHP entry points:
When routing to any PHP file (wp-login.php, wp-admin/index.php, etc.):
$_SERVER['SCRIPT_NAME']= the requested PHP file path (e.g.,/wp-login.php)$_SERVER['PHP_SELF']= same as SCRIPT_NAME$_SERVER['SCRIPT_FILENAME']= full filesystem path to the PHP fileFixed $_SERVER variables for pretty permalinks:
When routing non-existent URLs to index.php:
$_SERVER['SCRIPT_NAME']=/index.php$_SERVER['PHP_SELF']=/index.php$_SERVER['SCRIPT_FILENAME']= full path to index.php$_SERVER['REQUEST_URI']= unchanged, preserving the pretty URL2. features/server.feature
Test scenarios:
http://protocol and checks for "wp-login.php" in HTML outputwp option update permalink_structureto set permalink structure, then tests accessing default post with query parameterManual Testing Completed
✅ Direct PHP file access (test-entry.php) - $_SERVER variables correctly set
✅ Pretty permalink routing (/some-pretty-url/) - routed to index.php with correct variables
✅ Static file serving (test.txt) - served correctly by PHP's built-in server
✅ Edge case: directory with .php in name - handled correctly with pathinfo()
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.