REST API 404 or 403 Errors (Even Though It Should Work)

You’re building a block. Connecting a headless frontend. Or just trying to use the Site Editor. Everything seems correct. Then you hit the browser console and see it:

GET /wp-json/wp/v2/posts → 404 Not Found

Or worse:

403 Forbidden

The WordPress REST API should work out of the box. But sometimes it doesn’t. And the error messages can be misleading.

This guide explains why REST API requests fail with 404 or 403 errors — even when you’ve done nothing wrong — and how to fix them.

Table of Contents

  1. Understanding REST API Errors
  2. 404 Errors: “Not Found”
  3. 403 Errors: “Forbidden”
  4. Step-by-Step Troubleshooting
  5. Testing Your REST API

1. Understanding REST API Errors

The WordPress REST API is a powerful tool. It allows external applications (and the block editor) to interact with your site.

What should happen:

  • Visiting https://yoursite.com/wp-json/ should return a JSON object
  • Visiting https://yoursite.com/wp-json/wp/v2/posts should return a list of posts

What actually happens sometimes:

  • A 404 page (HTML, not JSON)
  • A blank white page
  • A 403 “Forbidden” message
  • An infinite redirect loop

The key insight: 404 and 403 errors on REST API endpoints usually aren’t authentication issues. They’re almost always server configuration problems.

ErrorWhat It MeansMost Common Cause
404Endpoint not foundPermalinks, .htaccess, or Nginx config
403Access deniedSecurity plugin, hosting firewall, or server rules

2. 404 Errors: “Not Found”

A 404 on wp-json means the server doesn’t recognize the REST API routes. The request reaches WordPress, but something is blocking the rewrite rules.

Cause #1: Permalinks Not Set to “Pretty”

The REST API requires pretty permalinks. If your permalinks are set to “Plain” (?p=123), REST routes return 404.

Check: Settings → Permalinks → Is anything other than “Plain” selected?

Fix: Select any option other than “Plain” (e.g., “Post name”) and click Save Changes.

Why this works: Saving permalinks regenerates the .htaccess file (Apache) or flushes rewrite rules.

Cause #2: Corrupted .htaccess File (Apache Servers)

On Apache servers, rewrite rules live in .htaccess. If this file is missing or corrupted, REST routes return 404.

Fix via WordPress:

  1. Go to Settings → Permalinks
  2. Click Save Changes (no need to change anything)
  3. This regenerates the rewrite rules

Fix via FTP:

  1. Connect via FTP
  2. Navigate to your WordPress root folder
  3. Look for .htaccess (enable hidden files if needed)
  4. If missing, create one with this content:

apache

# 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
  1. Save and refresh your site

Cause #3: Nginx Missing Rewrite Rules

If you use Nginx, you need explicit rewrite rules. The standard WordPress Nginx config must include:

nginx

location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~ ^/wp-json/ {
    try_files $uri $uri/ /index.php?$args;
}

Fix: Add the wp-json location block to your Nginx server configuration, then reload Nginx (sudo systemctl reload nginx).

Don’t have access? Contact your hosting support and ask them to ensure REST API rewrite rules are in place.

Cause #4: Plugin Blocking REST API

Some plugins intentionally disable the REST API for “security” (which is usually unnecessary and breaks functionality).

Common culprits:

  • Disable REST API plugins
  • Security plugins with REST API lockdown features
  • Maintenance mode plugins
  • Login lockdown plugins

Fix:

  1. Temporarily deactivate all plugins
  2. Test https://yoursite.com/wp-json/
  3. If it works, reactivate plugins one by one to find the culprit
  4. Reconfigure or replace the offending plugin

Cause #5: Hosting-Level Blocking

Some managed WordPress hosts block REST API access for unauthenticated users by default. This is rare, but happens.

Known hosts with this behavior (in certain configurations):

  • Some older WP Engine plans (now mostly resolved)
  • Some custom enterprise hosting setups

Fix: Contact your host and ask:

“Is the WordPress REST API enabled for unauthenticated requests? I’m getting a 404 on /wp-json/.”

3. 403 Errors: “Forbidden”

A 403 error means the server understood the request but is refusing to fulfill it. This is usually an authentication or security issue.

Cause #1: Security Plugin Blocking REST Access

Most security plugins have a feature to block REST API access for non-logged-in users.

Check your security plugin settings for:

  • “Disable REST API” or “REST API lockdown”
  • “Block unauthorized REST requests”
  • “Require authentication for REST API”

Fix: Whitelist the specific endpoints you need, or disable REST API blocking entirely (it doesn’t meaningfully improve security in most cases).

Popular plugins with REST restrictions:

  • Wordfence — Check “Brute Force Protection” settings
  • iThemes Security — Look for “REST API” settings
  • Sucuri — Firewall rules may block certain endpoints
  • All In One WP Security — “REST API” tab

Cause #2: Server-Level Blocking (ModSecurity)

Some hosting providers use ModSecurity or similar WAFs (Web Application Firewalls) that block REST API requests containing certain patterns.

Common patterns that trigger blocks:

  • Requests with many parameters
  • Requests containing SQL-like strings
  • Requests from certain user agents

Fix:

  1. Check your hosting control panel for ModSecurity logs
  2. Temporarily disable ModSecurity (if allowed) to test
  3. Ask your host to whitelist wp-json/* paths
  4. Or ask them to adjust the rule causing the false positive

Cause #3: .htaccess Deny Rules

Custom .htaccess rules may explicitly block access to wp-json.

Check your .htaccess for:

apache

Deny from all
<Files "wp-json">
    Deny from all
</Files>

Fix: Remove any rules that block wp-json or the REST API.

Cause #4: Missing or Incorrect Authentication (for Protected Routes)

Some REST API endpoints require authentication:

  • Creating/updating posts (requires edit_posts capability)
  • Deleting comments (requires moderate_comments)
  • Getting users (requires list_users)

If you’re calling these endpoints without authentication, you’ll get a 403.

Fix: Add authentication to your requests:

  • For JavaScript (block editor): Use wpApiSettings.nonce
  • For external apps: Use Application Passwords (WordPress 5.6+)
  • For custom code: Use cookie authentication or OAuth plugins

Example of adding nonce to fetch request:

javascript

fetch('/wp-json/wp/v2/posts', {
    headers: {
        'X-WP-Nonce': wpApiSettings.nonce
    }
})

Cause #5: Hosting Firewall (Cloudflare, Sucuri, etc.)

CDNs and firewalls sometimes block REST API requests, especially if they contain JSON payloads.

Fix:

  • Add a firewall rule to allow */wp-json/*
  • Temporarily pause the CDN/firewall to test
  • Check the firewall’s security logs for blocked requests

4. Step-by-Step Troubleshooting

Follow this checklist in order. Test after each step.

Step 1: Test the base REST endpoint

  • Visit https://yoursite.com/wp-json/ in your browser
  • You should see a JSON object with namedescriptionurl, etc.
  • If you see a 404 or 403 → proceed

Step 2: Save permalinks

  • Go to Settings → Permalinks
  • Click Save Changes (no need to change anything)
  • Test again

Step 3: Disable all plugins

  • Deactivate every plugin
  • Test https://yoursite.com/wp-json/
  • If it works → reactivate plugins one by one to find the culprit

Step 4: Switch to a default theme

  • Temporarily activate Twenty Twenty-Four or Twenty Twenty-Three
  • Test again
  • If this fixes it, your theme is blocking the REST API

Step 5: Check your .htaccess file

  • Via FTP, open .htaccess in your WordPress root
  • Ensure the default WordPress rules are present (see section 2, Cause #2)
  • If missing, add them and save

Step 6: Check server rewrite rules (Nginx only)

  • Ensure your Nginx config includes the wp-json location block
  • If you don’t have access, contact your host

Step 7: Check security plugins

  • Look for REST API blocking features (see section 3, Cause #1)
  • Temporarily disable the security plugin to test

Step 8: Check your hosting firewall

  • Check ModSecurity logs or hosting firewall logs
  • Temporarily disable (if possible) to test
  • Contact support to whitelist /wp-json/*

Step 9: Enable WordPress debugging
Add to wp-config.php:

php

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Then check wp-content/debug.log for REST API-related errors.

5. Testing Your REST API

Quick Test (Browser)

  1. Open your browser
  2. Visit: https://yoursite.com/wp-json/
  3. Expected result: JSON object, not HTML

Command Line Test

bash

curl https://yoursite.com/wp-json/wp/v2/posts

Expected output: JSON array of posts (may be empty).

Check HTTP Status Code Only

bash

curl -I https://yoursite.com/wp-json/

Expected: HTTP/1.1 200 OK (not 404, 403, or 301/302 redirects).

Test with Authentication (for protected endpoints)

bash

curl -X GET https://yoursite.com/wp-json/wp/v2/users/me \
  --header 'X-WP-Nonce: YOUR_NONCE' \
  --cookie 'wordpress_logged_in_YOUR_HASH'

Final Thoughts

REST API 404 and 403 errors are almost always server configuration or security plugin issues — not bugs in WordPress itself.

The golden rule: Start by saving permalinks. It’s simple, fast, and fixes 50% of 404 errors.

If that doesn’t work, disable all plugins and switch to a default theme. This isolates whether the problem is in your configuration or your hosting environment.

And remember: Most 403 errors are security plugins doing their job too aggressively. Review your security plugin’s REST API settings before assuming anything else is broken.

Was this post helpful?
Buy us a coffee!
Tags:

Free eBook!

Subscribe to our newsletter to receive it free!