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:
The requested URL /wordpress/wp-json/ was not found on this server
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
- Not a Multisite
- WP REST API plugin 2.0-beta9
- Apache 2.2.22
- Ubuntu 12.04.5
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!
I had moved the WordPress install from a subdirectory to another, so in my case the problem was due to the WordPress config in the
.htaccess
files. It was trying to redirect every page but the homepage to the old directory. It was just a matter of updatingolddir
tonewdir
... This tripped me up more than once so I thought I'd put it here...I had to manually make a
.htaccess
, set it tochmod 664
, and copy the permalink rules into it.I also played around with
mod rewrite
was enabled viaa2enmod
I solved this issue through following steps:
Navigate to ..\Apache24\conf\httpd.conf and search for
LoadModule rewrite_module modules/mod_rewrite.so
.Enable rewrite module by removing the
#
mark.Replace all the cases of
AllowOverride None
toAllowOverride All
.Don't forget to restart apache server. :)
It turned out to be a problem with the Apache configuration.
First, I deleted the
.htaccess
file in the root wordpress directory.Next, I navigated to
/etc/apache2/sites-enabled
and opened000-default
All of the
AllowOverride
variables were set to None, which I replaced withAll
.That did the trick!
UPDATED NEW WAY
I also faced similar problem in a local project. I used
index.php
after my project url and it worked.If it displays a 404 error then update permalinks first (see "Paged Navigation Doesn't Work" section
If it works, maybe you need to enable
mod_rewrite
, on ubuntu:Installation
If you're before 4.7:
Download plugin from here: http://v2.wp-api.org/
install and activate it.
Usage
To get all posts:
For the search functionality, searching for test post looks like this:
On WPEngine and WP 4.9.2 I only had to update permalinks to get fresh, newly installed site to return v2 API calls. What I did: