2

I just installed and activated the latest version of the WP REST API plugin. However, when I attempt to access a REST endpoint, I end up with the Apache 404 page.

$ curl -i 'http://example.com/wp-json/wp/v2/posts/1'
HTTP/1.1 404 Not Found
Date: Wed, 20 Jul 2016 01:23:25 GMT
Server: Apache/2.4.18 (Unix) PHP/5.6.23
Content-Length: 219
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /wp-json/wp/v2/posts/1 was not found on this server.</p>
</body></html>

That is -- WordPress itself is never invoked. I'd expect the above request to throw an error of some sort (since I'm attempting to connect unauthenticated). However, my WordPress system is being bypassed entirely.

I'm an experienced PHP developer here, but I only ever dip in and out of Wordpress dev so apologies in advance for a question that likely has an obvious answer. This bit of cryptic-to-me text from the installation instructions seems like it may be relevant

For full-flavored API support, you'll need to be using pretty permalinks to use the plugin, as it uses custom rewrite rules to power the API.

but not being familiar with WordPress' routing system (or equivalent), I'm not sure what my next steps should be in debugging this problem.

0

1 Answer 1

4

Try changing your permalinks structure. Within the dashboard go to Settings > Permalinks and select the Post Name structure. When this is done click Save Changes.

If Post Name is already selected, it might be worth clicking save changes again to reset the permalinks.

Update: Per the comments below, Wordpress does not, out of the box, ship with a .htaccess file for its frontend application. When you change permalink settings, Wordpress will attempt to write out a .htaccess file for your . If it doesn't have permission, the UI will update with a notification saying so, and you'll be able to find the required rules at the bottom of the page.

3
  • That did it @mbacon40 -- I'm a little confused though. I saw references to turning permalink structure "on" -- but there doesn't seem a way to turn it on and off? And before I switched it to "Post Name", it was set to "Custom Structure" -- is "Custom Structure" considered off? Am I crazy here? Commented Jul 22, 2016 at 22:18
  • There is not a way to turn the permalink structure "off". When the permalinks are set, WordPress sets rewrite rules within your .htaccess file. If you do not have these set, then the pretty permalinks will not work. When new paths are added to a WordPress site such as a new post type or in your case the path to the API endpoints, the rewrite rules in the .htaccess file need to be rewritten to accommodate them. This could be done manually but it is easier to let WordPress handle the rewrites.
    – Marc
    Commented Jul 25, 2016 at 14:40
  • you're life saver Commented Jul 8, 2017 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.