@@ -107,11 +107,15 @@ function ( $url ) {
107107 $ url = str_replace ( $ site_url_host , $ _SERVER ['HTTP_HOST ' ], $ url );
108108 }
109109
110+ $ url = str_replace ( 'https:// ' , 'http:// ' , $ url );
111+
110112 return $ url ;
111113 },
112114 20
113115);
114116
117+ add_filter ( 'got_url_rewrite ' , '__return_true ' );
118+
115119$ _SERVER ['SERVER_ADDR ' ] = gethostbyname ( $ _SERVER ['SERVER_NAME ' ] );
116120$ wpcli_server_root = $ _SERVER ['DOCUMENT_ROOT ' ];
117121// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
@@ -123,13 +127,24 @@ function ( $url ) {
123127 exit ;
124128 }
125129
126- if ( strpos ( $ wpcli_server_path , '.php ' ) !== false ) {
130+ // Check if this is a PHP file by examining the extension
131+ if ( pathinfo ( $ wpcli_server_path , PATHINFO_EXTENSION ) === 'php ' ) {
132+ // Set $_SERVER variables to mimic direct access to the PHP file
133+ $ _SERVER ['SCRIPT_NAME ' ] = $ wpcli_server_path ;
134+ $ _SERVER ['PHP_SELF ' ] = $ wpcli_server_path ;
135+ $ _SERVER ['SCRIPT_FILENAME ' ] = $ wpcli_server_root . $ wpcli_server_path ;
136+
127137 chdir ( dirname ( $ wpcli_server_root . $ wpcli_server_path ) );
128138 require_once $ wpcli_server_root . $ wpcli_server_path ;
129139 } else {
130140 return false ;
131141 }
132142} else {
143+ // File doesn't exist - route to index.php for pretty permalinks
144+ $ _SERVER ['SCRIPT_NAME ' ] = '/index.php ' ;
145+ $ _SERVER ['PHP_SELF ' ] = '/index.php ' ;
146+ $ _SERVER ['SCRIPT_FILENAME ' ] = $ wpcli_server_root . '/index.php ' ;
147+
133148 chdir ( $ wpcli_server_root );
134149 require_once 'index.php ' ;
135150}
0 commit comments