brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: use ?rest_route= when /wp-json/ gives a 404

WordPress
~/tips/tip-wordpress-rest-route-query-parameter

curl -s "https://example.com/?rest_route=/"

With plain permalinks the REST API lives behind a query string parameter instead of /wp-json/.

A fresh WordPress install, a curl request to /wp-json/, and a 404. It looks like the REST API is broken, but usually it’s just the permalink setting. There’s a way in that doesn’t touch the settings at all.

curl -s "https://example.com/?rest_route=/"

That returns the REST API index, the same thing /wp-json/ gives you with pretty permalinks. The official docs say it plainly: if you use non-pretty permalinks, you should pass the REST API route as a query string parameter. Their own example is the index route, http://oursite.com/?rest_route=/.

The same docs list this as the fix for a 404 on /wp-json/. They suggest you either enable pretty permalinks or use the rest_route parameter instead. For a quick check on a site you don’t want to reconfigure, the parameter is the faster path. For a site that people will use for real, I’d turn on pretty permalinks anyway.

Because the route sits in the query string, further parameters have to be added with & instead of a second ?. A request for the posts route with extra parameters would look like ?rest_route=/wp/v2/posts&per_page=1.

A caveat on that last point: the docs only show the index route as an example, so the posts example above is my reading of the rule and it was not run against a live site. If the index route answers, the same rule applies to the other routes.

Further reading: REST API handbook: key concepts

More WordPress tips curl -s "https://example.com/wp-json/wp/v2/posts/42?_embed" curl -s -D – -o /dev/null "https://example.com/wp-json/wp/v2/posts?per_page=100" 'You must be logged in.', add_filter( 'the_title', 'plugin_shout_title', 20 ); define( 'AUTOMATIC_UPDATER_DISABLED', true ); All WordPress tips (92) All topics

Link