REST API URL path processing bug?
-
In brief, the problem appears to be that my site’s “home” URL path is “wp”, which just happens to be a prefix of the REST API’s path prefix “wp-json”, so it’s stripping the prefix off and trying to match the rewrite rule patterns against “-json”. That breaks it.
So here’s more detailed information:
I’ve been tinkering with WordPress locally via Wampserver (3.0.6). I have added an alias to the embedded apache config, in the virtual host:
Alias “/wp” “c:\path\to\wordpress”
So to access wordpress, I go to
That’s also the site’s “home” URL (i.e. the actual “home” option setting in the wp_options db table). And it has worked fine, up until I started experimenting with the REST APIs.
I am accessing the REST API following a clue in the comments regarding a “path info request”, for example:
http://localhost/wp/index.php/wp-json/wp/v2/posts
When I do this, relevant PHP global values are:
_SERVER[‘PATH_INFO’]: /wp-json/wp/v2/posts
_SERVER[‘REQUEST_URI’]: /wp/index.php/wp-json/wp/v2/postsThe problem is in the post-processing of the path info, in WP::parse_request(). It’s stripping off the home path from the beginning of the path info value, which results in “-json/wp/v2/posts”. That means the rewrite rules aren’t matching as they should. If I comment out line 196, then it works. Also, it seems like if I hadn’t coincidentally created my apache alias with letters which formed a prefix of “wp-json”, this wouldn’t have happened (though I haven’t tested this; I’m not sure I can change the alias without also needing to hack WordPress settings like the “home” setting). So it seems like a subtle coincidence which may have revealed a bug.
Is this a bug? If the path info comes after “index.php” in the URL, and the home path comes before, why would the home path ever occur in the path info? Why would it need to be stripped?
My background: I’ve been a dev for many years, but this software stack is new to me. So it is possible I’ve messed something up too 🙂
The topic ‘REST API URL path processing bug?’ is closed to new replies.