Wordpress REST API(wp-api)404错误 [英] Wordpress REST API (wp-api) 404 Error

查看:579
本文介绍了Wordpress REST API(wp-api)404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用XAMPP进行本地开发时,已经使用Wordpress REST插件WP-API已有数月了.我最近将网站迁移到了EC2实例,并且一切正常,例外,无论何时尝试访问API上的任何端点,我现在都会收到带有以下消息的404:

I have been using the Wordpress REST plugin WP-API for months now while developing locally with XAMPP. I recently migrated my site to an EC2 instance and everything is working fine except I now get a 404 with the following message whenever I try to access any endpoint on the API:

在此服务器上找不到请求的URL/wordpress/wp-json/

The requested URL /wordpress/wp-json/ was not found on this server

启用了具有以下结构http://.../wordpress/sample-post/的漂亮的永久链接,当在浏览器中导航到特定帖子时,该链接可以正常工作.

Pretty permalinks are enabled with the following structure http://.../wordpress/sample-post/ which works fine when navigating to a specific post in the browser.

以下是有关我的设置的一些详细信息:

Here are some details about my setup:

  • WordPress 4.4.1
    • 不是多站点
    • Wordpress 4.4.1
      • Not a Multisite

      任何帮助将不胜感激,因为我经历了数小时的SO和WP支持论坛,并且没有任何想法.谢谢!

      Any help would be greatly appreciated as I have gone through SO and the WP Support forums for several hours and am out of ideas. Thank you!

      推荐答案

      更新的方式

      我在一个本地项目中也遇到了类似的问题. 我在项目网址后使用index.php ,并且有效.

      I also faced similar problem in a local project. I used index.php after my project url and it worked.

      http://localhost/myproject/index.php/wp-json/wp/v2/posts
      

      如果它显示404错误,则首先更新永久链接 (请参阅分页导航不起作用"部分

      If it displays a 404 error then update permalinks first (see "Paged Navigation Doesn't Work" section

      如果可行,也许您需要在ubuntu上启用mod_rewrite:

      If it works, maybe you need to enable mod_rewrite, on ubuntu:

      a2enmod rewrite
      sudo service apache2 restart
      

      安装

      REST API包含在WordPress 4.7中!不再需要插件,只需安装最新版本的WordPress,即可开始使用.

      The REST API is included in WordPress 4.7! Plugins are no longer required, just install the latest version of WordPress and you're ready to go.

      如果您早于4.7:

      1. 从此处下载插件: http://v2.wp-api.org/

      安装并激活它.

      用法

      获取所有帖子:

      Usage

      To get all posts:

      www.mysite.com/wp-json/wp/v2/posts
      

      对于搜索功能,搜索测试帖子看起来像这样:

      For the search functionality, searching for test post looks like this:

      /wp-json/wp/v2/posts?filter[s]=test
      

      这篇关于Wordpress REST API(wp-api)404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆