404 on http://localhost/wp-json/wp/v2/posts in wordpress using REST API V2

耗尽温柔 提交于 2019-12-23 04:10:17

问题


I am getting a 404 on http://localhost/wp-json/wp/v2/posts route. I changed permalink type to plain. Still got the same issue.

If its useful, I am ubuntu 16.04 desktop recent upgrade from 15.10, suffered issues with php5.6 to 7.0 upgrade. Am now on php 7.0

Edit1: Tried every other permalink setting combination, no results!


回答1:


You need to give permission to your wp-content folder. For the change the permission please use below command in terminal.

sudo chmod -R 755 wp-content/

After the change permission is still show 404 error then allow AllowOverride for apache, below is the step:

navigated to /etc/apache2/sites-enabled and opened 000-default

All of the AllowOverride variables were set to None, which I replaced with All.

After this change enable mod using below command:

 a2enmod rewrite

And restart the apache service below is the command:

sudo service apache2 restart



回答2:


http://localhost/?rest_route=/wp/v2/posts should works. Refer https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/ for details.




回答3:


Add index.php after your root link:

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

That worked for me.




回答4:


Check permissions and change it by chmod to 777



来源:https://stackoverflow.com/questions/44750315/404-on-http-localhost-wp-json-wp-v2-posts-in-wordpress-using-rest-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!