Fix router to properly set $_SERVER variables for entry points and pretty permalinks#89
Merged
swissspidy merged 9 commits intomainfrom Feb 5, 2026
Merged
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for pretty permalinks
Fix router to properly set $_SERVER variables for entry points and pretty permalinks
Nov 1, 2025
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
swissspidy
reviewed
Nov 1, 2025
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
swissspidy
reviewed
Feb 5, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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, flushes rewrite rules withwp rewrite flush, and tests actual pretty URL/hello-world/instead of plain permalinkManual 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.