diff --git a/composer.json b/composer.json index 1d86846..25cf7ae 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ }, "require-dev": { "wp-cli/entity-command": "^2", + "wp-cli/rewrite-command": "^2", "wp-cli/wp-cli-tests": "^5" }, "config": { diff --git a/features/server.feature b/features/server.feature index 6317757..65f6e9c 100644 --- a/features/server.feature +++ b/features/server.feature @@ -15,3 +15,25 @@ 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%/'` + And I run `wp rewrite flush` + + When I run `curl -sSL http://localhost:8183/hello-world/` + Then STDOUT should contain: + """ + Hello world! + """ diff --git a/router.php b/router.php index ff05d56..201aa28 100644 --- a/router.php +++ b/router.php @@ -107,6 +107,8 @@ function ( $url ) { $url = str_replace( $site_url_host, $_SERVER['HTTP_HOST'], $url ); } + $url = str_replace( 'https://', 'http://', $url ); + return $url; }, 20 @@ -125,13 +127,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'; }