One Allow-Origin value, methods, headers, optional credentials / Max-Age / Expose-Headers → Apache Header set or Nginx add_header … always.
We refuse * with credentials. We never send OPTIONS. Multi-origin allowlists belong in your API, not this snippet.
Exact origin (recommended) or * for anonymous requests — not with credentials.
Validate with browser DevTools Network or curl -i -H "Origin: …". You may still need explicit OPTIONS handling in your app or edge layer. Pair with TLS review via our
SSL Certificate Checker and Apache patterns from the .htaccess Generator.
Use it to paste a starting Apache or Nginx block for one front-end origin talking to one API.
Then still send a real OPTIONS from the browser (or curl -X OPTIONS -i) and watch the response.
Do not use * with credentials — we refuse that combination because browsers do.
Do not expect a multi-origin allowlist. Echoing Origin from a server allowlist is application code, not this snippet.
CORS is not authentication.
Apache: Header set inside <IfModule mod_headers.c>. Nginx: add_header … always;.
One Allow-Origin, methods, headers, optional Max-Age, credentials, Expose-Headers. Preferences sit in localStorage on this origin.
Front-end https://app.example.com, API on Apache, GET+POST+OPTIONS, credentials off:
Header set Access-Control-Allow-Origin "https://app.example.com" Header set Access-Control-Allow-Methods "GET, POST, OPTIONS" Header set Access-Control-Allow-Headers "Content-Type, Authorization"
If preflight still fails, your edge is not answering OPTIONS or Nginx nested add_header dropped the set. Fix routing, not this form.
Related: HTTP request builder for the client side of the same call.
add_header in server and location until duplicates or missing headers appear.* and cookies. Browsers refuse it; we do too..htaccess generator · HTTP request builder
No. Text only. You still test the live origin.
Not here. Implement an allowlist in the API or gateway.
Yes for Apache Header set. Missing module → ignore or 500 depending on host.
It is a starting snippet. Test error responses too — some stacks omit CORS on 4xx/5xx.