A CORS preflight request gets redirected and the browser blocks it
Redirect is not allowed for a preflight requestShort answer
Before certain cross-origin requests, the browser sends an OPTIONS preflight. If the server answers that preflight with a redirect, some browsers refuse to follow it and block the real request. Call the final URL directly, stop the server redirecting that route, or change the request so no preflight happens.
Fix it fast
1Find out which cause you have
Send the preflight by hand and look at the status line and the Location header. A 301, 302, 307 or 308 here confirms a redirect.
curl -i -X OPTIONS https://api.example.com/api/orders \ -H "Origin: https://app.example.com" \ -H "Access-Control-Request-Method: POST"2Match what you see, then jump to its fix
What does the error look like?
Redirect is not allowed for a preflight requestReason: CORS request external redirect not allowedRequest requires preflight, which is disallowed to follow cross-origin redirects
Cause 1 of 2
The URL your front end calls is not the final URL
1Check
The redirect target is the address the server wants. A frequent source is a Laravel route declared with Route::redirect, which answers 302 unless you pass another code.
grep -rn "Route::redirect\|Route::permanentRedirect" routes2Fix
Change the front-end URL to the address in Location. If you own the server, remove the redirect on the API route instead of redirecting.
// before
axios.post('https://api.example.com/api/orders', data);
// after: the URL from the Location header
axios.post('https://api.example.com/api/v2/orders', data);3Verify
The OPTIONS request now returns a success status with no Location header.
curl -i -X OPTIONS https://api.example.com/api/v2/orders -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: POST"Confirmed by developer.mozilla.org
Cause 2 of 2
The request triggers a preflight that the redirect then breaks
1Check
Requests with custom headers or non-simple methods are preflighted. Simple requests are not, so they are not blocked by this rule.
curl -i -X OPTIONS https://api.example.com/api/orders -H "Origin: https://app.example.com" -H "Access-Control-Request-Headers: content-type"2Fix
Where you cannot remove the redirect, change the server or the request so no preflight is needed. Otherwise make a simple request first, read the final address from Response.url, and send the real request there. This workaround does not work when the preflight comes from an Authorization header.
const probe = await fetch('https://api.example.com/api/orders');
const finalUrl = probe.url;
await fetch(finalUrl, { method: 'POST', body: JSON.stringify(data) });3Verify
The browser console shows no CORS error and the network tab shows the real request.
# open DevTools, Network tab, and filter by the API hostConfirmed by developer.mozilla.org
How do I stop it coming back?
- Store the API base URL in one place and keep it equal to the final address.
- Test every API route with a curl OPTIONS request after changing routes or the server's redirect rules.
- Do not mix a redirecting route with a CORS-enabled API path.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
Related fixes
Back end
Browser blocks your Laravel API with a CORS error
Response to preflight request doesn't pass access control check
Laravel answers CORS preflights itself through its HandleCors middleware, driven by config/cors.php.
3 causes, each with a fixBack end
Laravel CORS settings have no effect: missing config/cors.php, paths and cache
Response to preflight request doesn't pass access control check
Laravel answers CORS preflights itself through the HandleCors middleware, but only for URLs listed in the paths option of config/cors.php.
4 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ASP.NET Core has CORS set up but the browser still blocks the request
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
ASP.NET Core only adds CORS headers when a policy matches the request.
6 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fix