当我访问WordPress网站时www.example.com/wp-json/
我发现了404错误。
`{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}`
但是,如果我使用
www.example.com/wp-json/wp/v2/
.
我的永久链接设置为/%year%/%monthnum%/%postname%/
, 以下是我的nginx配置设置的一部分:
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.
}
我在互联网上搜索了一下,大多数问题似乎都是由不正确的永久链接设置和引起的。htaccess(Apache),但很少提及与nginx相关的案例。你知道这是什么原因吗?怎么解决?
Update
如果我跑步
curl -i www.example.com/wp-json
, 这就是我得到的:
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)
随着WordPress 4.7.3的发布,这个bug已经被修复。解决方法
unset ($_SERVER[\'PATH_INFO\']);
不再需要。