Fix “No route was found matching the URL and request method” in the WordPress REST API

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.

Quick fixes first

  1. Does the REST API index load? Visit https://yoursite.com/wp-json/. You should see a JSON index of namespaces.
    • If it 404s: go to Settings → Permalinks and click Save (flushes rewrites). Then try /wp-json/ again.
    • If your permalinks are “Plain,” test: https://yoursite.com/?rest_route=/wp/v2/types.
  2. Use the correct HTTP method. Many routes are 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
  3. Flush rewrites / restore default rules.
    • Dashboard: Settings → Permalinks → Save.
    • WP‑CLI:
      wp rewrite flush --hard
    • Apache default .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
    • Nginx server block:
      location / {
          try_files $uri $uri/ /index.php?$args;
      }

Confirm the route actually exists

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:

  • The plugin providing it may be inactive, loading late, or erroring out. Temporarily switch to a default theme and disable other plugins to isolate.
  • For custom code, ensure you register routes on 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

Match the required HTTP method

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

Rule out security/CDN blocks

Security layers can block or rewrite /wp-json paths, causing 404s or mismatches:

  • Temporarily disable WAF/CDN rules (Cloudflare, ModSecurity) and security plugins. Whitelist /wp-json/*.
  • Disable “REST API disable” snippets/filters (common in hardening guides). Look for code hooking rest_authentication_errors that denies requests.

Did someone change the REST prefix?

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).

Plugin examples

  • WooCommerce: core routes under /wp-json/wc/v3/… (GET for reads, POST/PUT for writes). Make sure WooCommerce is active and not blocked by server rules.
  • Block Editor: relies on /wp/v2/* routes. If Site Health flags REST errors, fix those first.

Troubleshooting checklist

  • /wp-json/ returns JSON index (or ?rest_route=… works on Plain permalinks).
  • Permalinks saved; correct Apache/Nginx rewrite in place.
  • Using the documented HTTP method for that route.
  • Route visible in the REST index; plugin providing it is active.
  • No security/WAF blocks on /wp-json/*.
  • Prefix hasn’t changed—or your client now targets the new prefix.

When to escalate

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.

Helpful references

Routes & Endpoints (REST API Handbook) ·
Site Health REST availability test ·
Nginx & WordPress ·
rest_url_prefix filter