From 3daa06328629c69f0c69426dd08c7459e1583400 Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Sun, 19 Feb 2017 03:27:13 +0000 Subject: [PATCH] REST API: Correctly serve the index with PATH_INFO When hitting the index, `untrailingslashit()` would make the REST route empty, which would then use the fallback inside WP_REST_Server. This isn't a problem most of the time, but WP_REST_Server contains a fallback to PATH_INFO. Combined with PATH_INFO permalinks, this would give a 404 on the API index, as it attempts to look up a route for "/wp-json/". Props ccprog. Merges [39923] to the 4.7 branch. Fixes #39432. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40079 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rest-api.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 5b62d96fce..b5e5d45e88 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -264,7 +264,11 @@ function rest_api_loaded() { $server = rest_get_server(); // Fire off the request. - $server->serve_request( untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] ) ); + $route = untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] ); + if ( empty( $route ) ) { + $route = '/'; + } + $server->serve_request( $route ); // We're done. die();