Skip to content

Commit 7e50de8

Browse files
committed
Set PATH_INFO
1 parent 10d89c0 commit 7e50de8

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

router.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,34 @@ static function ( $buffer ) {
137137
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
138138
$wpcli_server_path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' );
139139

140-
if ( file_exists( $wpcli_server_root . $wpcli_server_path ) ) {
141-
if ( is_dir( $wpcli_server_root . $wpcli_server_path ) && substr( $wpcli_server_path, -1 ) !== '/' ) {
140+
$wpcli_server_file = $wpcli_server_root . $wpcli_server_path;
141+
// Normalize slashes for file operations
142+
$wpcli_server_file = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $wpcli_server_file );
143+
144+
if ( file_exists( $wpcli_server_file ) ) {
145+
if ( is_dir( $wpcli_server_file ) && substr( $wpcli_server_path, -1 ) !== '/' ) {
142146
header( "Location: $wpcli_server_path/" );
143147
exit;
144148
}
145149

146150
// Check if this is a PHP file by examining the extension
147-
if ( pathinfo( $wpcli_server_path, PATHINFO_EXTENSION ) === 'php' ) {
151+
if ( pathinfo( $wpcli_server_file, PATHINFO_EXTENSION ) === 'php' ) {
148152
// Set $_SERVER variables to mimic direct access to the PHP file
149153
$_SERVER['SCRIPT_NAME'] = $wpcli_server_path;
150154
$_SERVER['PHP_SELF'] = $wpcli_server_path;
151-
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . $wpcli_server_path;
155+
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_file;
152156

153-
chdir( dirname( $wpcli_server_root . $wpcli_server_path ) );
154-
require_once $wpcli_server_root . $wpcli_server_path;
157+
chdir( dirname( $wpcli_server_file ) );
158+
require_once $wpcli_server_file;
155159
} else {
156160
return false;
157161
}
158162
} else {
159163
// File doesn't exist - route to index.php for pretty permalinks
160164
$_SERVER['SCRIPT_NAME'] = '/index.php';
161165
$_SERVER['PHP_SELF'] = '/index.php';
162-
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . '/index.php';
166+
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . DIRECTORY_SEPARATOR . 'index.php';
167+
$_SERVER['PATH_INFO'] = $wpcli_server_path; // Help WordPress parse request
163168

164169
chdir( $wpcli_server_root );
165170
require_once 'index.php';

0 commit comments

Comments
 (0)