Why does /wp-json/ not work on the “plain” permalink structure?

Say you start with a server that is completely empty. You haven’t installed WordPress yet. Now if you visit those wp-json URLs, your server goes and looks for corresponding directories / files that match your request, and of course it is empty, so as you would expect, you get 404 errors.

Now install default WordPress, plain permalinks. Visit those same URLs, and… still 404s. Why? Go and look for those directories on your server. They are still not there, this hasn’t changed simply by installing WordPress.

Now enable Pretty Permalinks. You are able to visit those JSON URLs and they work despite those physical directories still not being there.

What has changed?

Enabling Pretty Permalinks creates / adds some lines to an .htaccess file, which activates a module that is part of your server’s software. Now instead of returning 404 errors when your server discovers that the requested directories / files don’t exist, it hands those requests over to WordPress, so they can be resolved by WordPress internally.

As for how to use the REST API with plain permalinks, get_rest_url() will tell you, it will be in the format ?rest_route= when Pretty Permalinks are not enabled.

Leave a Comment