Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk9 min

How to Enable CORS Headers on Apache

A practical Apache CORS guide covering mod_headers, explicit and wildcard origins, credentials, preflight requests, configuration locations, testing, and common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable CORS on Apache by loading mod_headers and using its Header directive to add the required Access-Control-Allow-* response headers. You can place the directives in the main server configuration, a VirtualHost, a directory block, or an allowed .htaccess file. The correct location depends on the access your hosting account gives you.

Start with a specific approved origin for an application, add the method and header permissions required by its preflight request, and use Access-Control-Allow-Credentials: true only when credentials are genuinely needed. If Apache chooses an origin from an allowlist, return that origin and send Vary: Origin. Test both the real request and the browser’s OPTIONS preflight; a successful server response is not enough if the browser cannot find compatible CORS headers.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What CORS headers do

Cross-Origin Resource Sharing (CORS) is a browser security mechanism. A page loaded from one origin can request a resource from another origin, but browser scripts can read the response only when the response headers authorize that requesting origin. The server, not the browser application code, supplies that permission.

MDN describes Access-Control-Allow-Origin as the response header that indicates whether a response can be shared with requesting code from the given origin. Apache does not implement the policy automatically: it emits the headers through mod_headers, which provides the Header directive for modifying HTTP request and response headers.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

An origin consists of the scheme, host, and port. Therefore, https://app.example.com, http://app.example.com, and https://app.example.com:8443 are different origins. The value Apache returns must match the browser’s Origin value exactly when you use an explicit policy.

Before changing Apache

Identify the requesting origin

Write down the exact origin of the front-end application, including http or https and any non-default port. Do not use a full URL with a path, query string, or fragment in Access-Control-Allow-Origin; the value is an origin only.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm where you can configure headers

Server administrators can normally use the main Apache configuration or a virtual-host definition. Some installations also permit directory-level configuration. Shared hosting may allow only a site or directory .htaccess file, and the host must permit the relevant override class. If you cannot load modules or change headers in any permitted context, the application or hosting provider must supply the configuration.

Make sure mod_headers is loaded

The Header directive belongs to Apache’s mod_headers module. If Apache reports that the directive is unknown, or silently ignores a configuration because the module is unavailable, ask the administrator to load mod_headers before troubleshooting the CORS policy itself. The exact module-enabling procedure varies by operating system and hosting service, so use that environment’s documented Apache reload process.

Choose an origin policy first

Fixed explicit origin

For a browser application with a known origin, an explicit value is the safest starting point:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "https://app.example.com"
</IfModule>

This tells a browser that responses may be shared with code from exactly https://app.example.com. Replace the example with the real origin. If the application has separate development and production origins, decide deliberately whether both should be allowed; do not broaden the value merely to make an error disappear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Wildcard origin

For a genuinely public resource and requests that do not use credentials, Apache can return a wildcard:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

The wildcard is a broad permission. It does not work for credentialed browser requests. A private API, user-specific response, or any request that relies on cookies or other browser credentials should use an explicit approved origin instead.

Allowlist selected origins

When several known applications need access, maintain an allowlist and have the server select the requesting origin only when it is present in that list. The response should contain the selected origin, not an arbitrary value copied from the request. Add:

Vary: Origin

Vary: Origin tells caches that the representation can differ according to the request’s Origin header. Without it, a cached response generated for one allowed origin could be reused for another origin. Never reflect every incoming Origin value without validation. Also avoid Access-Control-Allow-Origin: null; MDN documents that hostile documents can obtain a null origin.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add the headers required by the request

Access-Control-Allow-Origin is the essential permission, but a browser’s preflight may require additional response headers. Add only what the application needs.

Allow methods

If the browser wants to use a method beyond the simple request cases, return Access-Control-Allow-Methods with the methods the endpoint actually supports. For example:

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "https://app.example.com"
    Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
</IfModule>

Do not list methods merely because they are convenient. The method list is part of the boundary around the resource.

Allow request headers

If the preflight asks to send headers such as a content type or an application-specific header, return Access-Control-Allow-Headers covering the headers the endpoint accepts:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<IfModule mod_headers.c>
    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"
</IfModule>

The names requested by the browser’s preflight must be covered by the server’s response. Remove entries that the application does not use.

Allow credentials only when needed

Credentialed cross-origin requests require an explicit origin and an affirmative credentials header:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "https://app.example.com"
    Header set Access-Control-Allow-Credentials "true"
</IfModule>

Do not combine Access-Control-Allow-Credentials: true with Access-Control-Allow-Origin: *; wildcard origin handling does not support credentialed browser requests. Keep the credential decision consistent on both the preflight response and the actual response.

Where to put the directives

Location Control and auditability When to use it Important limitation
Main server configuration Highest central control and easiest policy-wide auditing Use when you administer Apache and want one managed policy Requires administrator access and a configuration reload
VirtualHost Central control scoped to one site or host Use when different sites need different CORS policies Requires virtual-host configuration access
Directory context Scopes headers to a directory or application area Use when only one path should be cross-origin accessible Effective placement depends on the surrounding Apache configuration
.htaccess Per-directory control without editing the main configuration Use on hosting that permits the required override and where you lack central access Adds per-request processing overhead and is harder to audit globally

Apache documents mod_headers as usable in server, virtual-host, directory, and permitted .htaccess contexts. MDN notes that .htaccess lets users configure a directory without changing the main configuration, but recommends central configuration when it is available because distributed files add processing overhead.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Step-by-step: configure a fixed-origin application

  1. Record the origin. Copy the front end’s exact scheme, host, and port from the browser’s request. Use that value, without a path, in Access-Control-Allow-Origin.
  2. Select the narrowest Apache context. Prefer the main server or the relevant VirtualHost when you control Apache. Use a directory block when only one application path needs CORS. Use .htaccess only when central configuration is unavailable and overrides are permitted.
  3. Load mod_headers. Have the administrator enable the module if it is not loaded. Keep the <IfModule mod_headers.c> wrapper when the same file may be deployed across systems, but do not mistake a skipped block for a working policy.
  4. Add the origin header. Start with the fixed-origin snippet. Add Access-Control-Allow-Methods and Access-Control-Allow-Headers only for methods and request headers that the browser’s preflight requires.
  5. Decide on credentials. If the request uses browser credentials, replace any wildcard with the explicit origin and add Access-Control-Allow-Credentials: true. Otherwise, leave the credentials header out.
  6. Reload or deploy Apache. Use the normal configuration validation and reload procedure for your installation. If Apache refuses the configuration, correct that syntax error before testing CORS.
  7. Check the actual response and preflight. Inspect both responses in browser developer tools or with an HTTP client. Confirm that the returned origin, methods, headers, and credentials setting match the request.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handling the OPTIONS preflight

A browser sends an OPTIONS preflight when a cross-origin request needs permission before the real method or headers are used. The preflight includes the requesting Origin, the intended method, and, when applicable, the requested header names. Apache’s response must authorize those values.

What to verify

  • Access-Control-Allow-Origin exactly matches the requesting origin, or is the permitted wildcard for a non-credentialed public request.
  • Access-Control-Allow-Methods includes the intended method.
  • Access-Control-Allow-Headers includes the headers the browser requested.
  • Access-Control-Allow-Credentials: true is present when the application uses credentials and the origin is explicit.

Apply the policy to the preflight response as well as the actual response. A configuration that adds the header only to successful application responses can still fail when the OPTIONS request reaches a different handler or location.

How to test Apache CORS

Use browser developer tools

  1. Open the browser’s Network panel and reproduce the cross-origin action.
  2. Find the actual request and inspect its response headers.
  3. If the browser sent an OPTIONS request, inspect that response separately.
  4. Compare the request’s Origin, requested method, and requested headers with Apache’s allow headers.
  5. Read the browser’s CORS error literally; it commonly identifies a missing origin, method, header, or credential permission.

Use an HTTP client for header inspection

An HTTP client can show what Apache returned, but it does not enforce browser CORS rules. Send one request representing the actual operation and another OPTIONS request containing the intended origin, method, and headers. This separates an Apache response problem from a browser policy decision. A server may return a normal status and body while the browser still blocks JavaScript from reading it because the response header is missing or incompatible.

Common failures and precise fixes

The header is absent

Check that mod_headers is loaded, that the directive is in a context Apache reads, and that an .htaccess override is permitted. Verify that you edited the active virtual host or directory rather than an unused configuration file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The origin does not match

Compare the response value character by character with the request’s Origin. Scheme, hostname, port, and spelling all matter. A production HTTPS origin does not match its HTTP development counterpart.

Preflight fails on a method

Read the method named by the preflight and add it to Access-Control-Allow-Methods only if the endpoint is intended to support it. Also ensure the OPTIONS request reaches the configuration that emits the CORS headers.

Preflight fails on a header

Compare the browser’s requested header names with Access-Control-Allow-Headers. Add the required names deliberately, and remove unused permissions after the application no longer needs them.

Credentials and wildcard are mixed

Replace * with the exact approved origin and return Access-Control-Allow-Credentials: true consistently on preflight and actual responses. A wildcard cannot authorize a credentialed browser request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One origin works while another receives the wrong response

If Apache selects an origin dynamically, return only an allowlisted value and add Vary: Origin. This prevents caches from treating a response generated for one origin as interchangeable with a response for another.

An apparently successful response is blocked

CORS controls whether browser scripts may access the response, not whether Apache can generate a response. Inspect the response headers rather than relying on the HTTP status or visible server body. Missing or incompatible CORS headers cause the browser to block script access even when the server returned content.

Security checklist

  • Allow only the origins the application needs.
  • Use explicit origins for private or credentialed APIs.
  • List only required methods and request headers.
  • Validate every dynamically selected origin against a maintained allowlist.
  • Never reflect arbitrary Origin values.
  • Avoid Access-Control-Allow-Origin: null.
  • Add Vary: Origin whenever the returned origin changes by request.
  • Keep credential settings identical and intentional on preflight and actual responses.
  • Test normal cross-origin requests and OPTIONS preflights after every policy change.

Wildcard or explicit origin: which should you use?

Policy Security scope Credentials Operational effort
* Any origin may read a public, non-credentialed response Not supported for credentialed browser requests Simple, but broad; unsuitable for private user data
One explicit origin Only the named application origin may read the response Supports credentials when the credentials header is also enabled Simple to audit; requires separate decisions for other environments
Validated allowlist Only origins present in the server’s allowlist are returned Supports credentials when each selected origin is explicit and configured consistently Requires origin-selection logic and Vary: Origin

Final decision

For most Apache applications, begin with mod_headers and a fixed explicit origin in the narrowest centrally managed context available. Add method, header, and credential permissions only when the browser’s preflight and application behavior require them. Reserve * for public, non-credentialed resources; use a validated allowlist with Vary: Origin when several approved origins must be supported. Verify both the actual response and the OPTIONS preflight so the browser, not just Apache, confirms the policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.