I’m given this error:

https://image.prntscr.com/image/yUjTXILmQR6lbpAFIb2CyA.png

When trying to access http://127.0.0.1/wordpress/wp-json/wp/v2/posts/ but if I change my permalink structure to “Day and Name”, it works.

Problem is – everyone’s default installation is using “plain”, does this mean most people don’t have access to the default-enabled WP-JSON?

How come?

Here’s a dump of my .htaccess located in the /wordpress/ folder:

# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE

# BEGIN WordPress

# END WordPress

Also, it would be nice if someone could shed some light into why this issue appears, I feel as if permalinks are a big thing in WordPress but you almost never get to meet them.

1 Answer
1

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 Reply

Your email address will not be published. Required fields are marked *