The WordPress REST API returns “No route was found matching the URL and request method.” when the requested path (e.g., /wp-json/wp/v2/posts) doesn’t match any registered endpoint for the HTTP method you used. This guide walks you through quick checks and deeper fixes: confirm your REST base works, flush permalinks/rewrites, verify the correct HTTP verb, ensure the route exists, and rule out security or server config issues.
These steps apply to core endpoints (like /wp/v2/*) and plugin routes (WooCommerce, Contact Form 7, etc.).
My WordPress site keeps returning “No route was found matching the URL and request method” when calling the REST API. How do I fix it?
That message means WordPress can’t find an endpoint for the URL + HTTP method you sent. Work through these fixes in order. Most issues are resolved by steps 1–3.
https://yoursite.com/wp-json/. You should see a JSON index of namespaces.
/wp-json/ again.https://yoursite.com/?rest_route=/wp/v2/types.GET-only. If you send POST/PUT, you’ll get this error.
# Good: GET posts
curl -i https://yoursite.com/wp-json/wp/v2/posts?per_page=1
# Wrong method example (may trigger the error)
curl -i -X POST https://yoursite.com/wp-json/wp/v2/posts
wp rewrite flush --hard
.htaccess (root install):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
location / {
try_files $uri $uri/ /index.php?$args;
}
Open /wp-json/ and look for the namespaces and routes that include your endpoint. For example, core posts live under /wp/v2/posts. If you don’t see the route:
rest_api_init and your permission_callback returns true or a proper capability check.Optional (CLI): list routes. If you have the REST command package installed:
# Install once:
wp package install wp-cli/restful
# Then:
wp rest route list | grep wp\/v2
A single route can have multiple endpoints bound to specific verbs (e.g., GET for read, POST for create). If you call a route with a verb it doesn’t implement, WordPress reports “No route was found…”. Check your request method and try again with the documented verb.
# Example: read a single post (GET)
curl -i https://yoursite.com/wp-json/wp/v2/posts/123
# Example: update requires authentication + PUT/PATCH
curl -i -X PUT -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"title":"New Title"}' \
https://yoursite.com/wp-json/wp/v2/posts/123
Security layers can block or rewrite /wp-json paths, causing 404s or mismatches:
/wp-json/*.rest_authentication_errors that denies requests.The default REST base is /wp-json, but it can be changed via the rest_url_prefix filter. Confirm the actual base:
# Prints your site’s REST base (e.g., https://yoursite.com/wp-json/)
wp eval "echo rest_url();"
If it returns /api (or similar), adjust your client requests to match (e.g., /api/wp/v2/posts).
/wp-json/wc/v3/… (GET for reads, POST/PUT for writes). Make sure WooCommerce is active and not blocked by server rules./wp/v2/* routes. If Site Health flags REST errors, fix those first./wp-json/ returns JSON index (or ?rest_route=… works on Plain permalinks)./wp-json/*.If everything checks out but the error persists, look for fatal errors during rest_api_init (enable WP_DEBUG_LOG) and inspect the server error log. A plugin fatal before route registration can silently remove endpoints.
Routes & Endpoints (REST API Handbook) ·
Site Health REST availability test ·
Nginx & WordPress ·
rest_url_prefix filter