wp-json/ return 404, but wp-json/wp/v2/ works fine on my nginx server


When I access my WordPress site as www.example.com/wp-json/ I got this 404 error.

`{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}`

But the REST api return the correct json object if I use the url of www.example.com/wp-json/wp/v2/.

My permalink is setup as /%year%/%monthnum%/%postname%/, and here is part of my nginx configuration settings:

server {

    root /var/www/html;
    index index.php index.html index.htm;

    location / {
      try_files $uri $uri/ /index.php$is_args$args;

    # other location directives related to php, cache, etc.


I searched on Internet and most of the problems seems to be caused by incorrect permalink setting and .htaccess (Apache), but seldom mentioned about the case related to nginx. Any idea what cause this and how to solve it?


If I run curl -i www.example.com/wp-json, this is what I get:

HTTP/1.1 404 Not Found
Server: nginx
Date: Sun, 29 Jan 2017 11:58:21 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Robots-Tag: noindex
Link: <https://example.com/wp-json/>; rel="https://api.w.org/"
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type

{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}

Latest Update (7 Mar 2017)

With the release of WordPress 4.7.3, this bug has been fixed. The workaround unset ($_SERVER['PATH_INFO']); no longer needed.

hcheung 2 months 0 Answers 14 views 0

Leave an answer