diff --git a/features/server.feature b/features/server.feature index 6317757..29b0787 100644 --- a/features/server.feature +++ b/features/server.feature @@ -15,3 +15,24 @@ Feature: Serve WordPress locally When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt` And I run `cmp /tmp/license.txt license.txt` Then STDOUT should be empty + + Scenario: Access wp-login.php + Given a WP install + And I launch in the background `wp server --host=localhost --port=8182` + + When I run `curl -sS http://localhost:8182/wp-login.php` + Then STDOUT should contain: + """ + wp-login.php + """ + + Scenario: Pretty permalinks + Given a WP install + And I launch in the background `wp server --host=localhost --port=8183` + And I run `wp option update permalink_structure '/%postname%/'` + + When I run `curl -sS http://localhost:8183/?p=1` + Then STDOUT should contain: + """ + Hello world! + """ diff --git a/router.php b/router.php index 8c6daa9..e87319f 100644 --- a/router.php +++ b/router.php @@ -123,13 +123,24 @@ function ( $url ) { exit; } - if ( strpos( $wpcli_server_path, '.php' ) !== false ) { + // Check if this is a PHP file by examining the extension + if ( pathinfo( $wpcli_server_path, PATHINFO_EXTENSION ) === 'php' ) { + // Set $_SERVER variables to mimic direct access to the PHP file + $_SERVER['SCRIPT_NAME'] = $wpcli_server_path; + $_SERVER['PHP_SELF'] = $wpcli_server_path; + $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . $wpcli_server_path; + chdir( dirname( $wpcli_server_root . $wpcli_server_path ) ); require_once $wpcli_server_root . $wpcli_server_path; } else { return false; } } else { + // File doesn't exist - route to index.php for pretty permalinks + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['PHP_SELF'] = '/index.php'; + $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . '/index.php'; + chdir( $wpcli_server_root ); require_once 'index.php'; }