CORS preflight request doesn't pass access control check: It does not have HTTP ok status

CORS preflight request doesn't pass access control check: It does not have HTTP ok status

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

CORS Preflight Failures in WordPress REST API with JWT Auth

When your frontend application makes a POST or GET request to a WordPress REST API endpoint secured by JSON Web Tokens (JWT), you might encounter the error: "Access to XMLHttpRequest at '...' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status."

This specific error message, It does not have HTTP ok status, is the critical clue. It means the browser sent an OPTIONS request (the preflight), but the server responded with a status code other than 200 OK. In your specific case, the .htaccess configuration includes this block:

RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

While this rule attempts to return a 200 status for preflight requests, it is fundamentally flawed when combined with the CORS headers you defined later in the file. The issue stems from how Apache handles header directives relative to redirect flags and environment variable propagation.

The Conflict Between Redirect Flags and Headers

Your .htaccess logic attempts to handle CORS by first checking for an Authorization header, setting a corresponding environment variable, and then defining headers based on that variable. However, the sequence of operations creates a logical trap.

When Apache processes the RewriteRule ^(.*)$ $1 [R=200,L], it issues an immediate redirect to the current URI with a status code of 200. While a 200 status technically satisfies the "HTTP OK status" requirement, the way you are setting the headers immediately after this rewrite block is problematic.

Specifically, look at these lines:

Header set Access-Control-Allow-Origin %{CORS}e env=CORS
Header set Access-Control-Allow-Credentials "true" env=CORS

The env=CORS syntax tells Apache to only add these headers if the CORS environment variable is set. The SetEnvIf directive that sets this variable relies on:

SetEnvIf Origin "^(http://localhost:3000)$" CORS=$0

This logic appears sound, but there is a subtle interaction with the RewriteRule. When a preflight request hits the server, Apache processes the rewrite rules first. If the RewriteCond for the OPTIONS method matches, the rule executes and issues a redirect response. In many Apache configurations, once a response body or specific headers are generated by a rewrite rule with the [L] flag, subsequent header directives in the same context might not apply as expected, or the environment variable check fails because the request flow has already been terminated by the rewrite action.

More critically, if the server returns a 200 OK status code but omits the critical headers like Access-Control-Allow-Origin, the browser treats this as a failure to pass the access control check. The error message explicitly states the preflight did not pass the access control check, which implies the browser received a 200 status but found the required CORS headers missing or malformed.

Debugging the Header Output

To confirm whether the headers are being sent at all, you need to inspect the raw response from your server. Since Postman works fine, it is bypassing these browser-level checks. You can verify what your server is actually returning by adding a debug directive to your .htaccess file:

Header set Access-Control-Allow-Origin "*" env=CORS
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD" env=CORS
Header set Access-Control-Allow-Headers "*"

Note the removal of env=CORS from the headers allowing all origins temporarily. If you still see the error in the browser console, it confirms that the environment variable CORS is never populated for preflight requests, or the headers are being stripped before reaching the client.

A common pitfall with .htaccess and CORS is ensuring that the headers are sent before any content negotiation or file checks interfere with the response. If your server returns a 403 Forbidden or 404 Not Found for the OPTIONS method specifically, you will see the "It does not have HTTP ok status" error.

Recommended Configuration Pattern

To resolve this reliably without relying on fragile environment variable chains that might break during rewrite cycles, consider using a dedicated CORS handler or simplifying the logic. A more robust approach in .htaccess often involves setting headers directly without conditional environment variables unless absolutely necessary:

<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
  Header set Access-Control-Allow-Credentials "true"
  Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD"
  Header set Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With"
</IfModule>

However, since you are dealing with a specific origin (http://localhost:3000) and JWT authentication, you should restrict the Access-Control-Allow-Origin to that exact value for security. The key is ensuring the server responds to OPTIONS requests with a 200 status code and includes all necessary headers in that specific response.

If you continue to face issues where Postman works but the browser fails, it is highly likely that the request is hitting a different entry point or the .htaccess rules are being overridden by other server configurations. Ensure that the mod_rewrite and mod_headers modules are active and that no other plugin or theme is injecting conflicting headers before your own block executes.

For developers building similar integrations, understanding the order of execution in Apache is vital: Rewrite Rules -> Header Sets -> Content Generation. If a rule redirects or terminates the request prematurely, subsequent header directives may never take effect, leading to the exact "HTTP ok status" error you are experiencing.

Our network