October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Update CORS Rules in .htaccess on WordPress and Apache

A practical guide to updating CORS headers in WordPress and Apache .htaccess, including wildcard versus exact origins, preflight requests, credentials, WordPress conflicts, testing, and failure recovery.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To fix a missing Access-Control-Allow-Origin header, add a narrowly scoped Apache Header rule in the .htaccess file that serves the API or assets, then verify the actual response—including any OPTIONS preflight. This works only when the host allows FileInfo overrides and Apache has mod_headers loaded. Use an exact frontend origin for private or credentialed requests; reserve * for public, anonymous access.

The header is a browser permission, not an access-control system. WordPress authentication, authorization checks, nonces, and API permissions still have to protect the endpoint.

As an Amazon Associate I earn from qualifying purchases.

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

What CORS changes in Apache

Cross-Origin Resource Sharing (CORS) is enforced by browsers. A page served from one origin—defined by scheme, host, and port—may request a resource from another origin, but the browser will expose the response to JavaScript only when the response contains an acceptable CORS policy.

Apache sends that policy as HTTP response headers. The most important one is Access-Control-Allow-Origin. A rule in .htaccess changes Apache’s response; it does not change the browser’s request policy and cannot grant a user permission they do not already have on the WordPress endpoint.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

For example, https://app.example.com, https://app.example.com:8443, and http://app.example.com are different origins. An allowed value must match the requesting origin exactly. Do not include a path such as /dashboard or append a trailing slash.

Check whether .htaccess can work on your server

Before editing anything, confirm the Apache prerequisites with your host or server administrator. A syntactically correct rule has no effect when the server ignores the file, and it can produce a 500 error when the directive is forbidden.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Overrides must be enabled. Apache controls this with AllowOverride and, on newer configurations, AllowOverrideList. The Header directive belongs to the FileInfo override class.
  • mod_headers must be loaded. Apache’s Header directive is supplied by this module and is available in server, virtual-host, directory, and permitted .htaccess contexts.
  • The file must be in the right directory. A .htaccess file applies to its directory and descendants when overrides are enabled. A rule in a WordPress document-root file will not automatically govern a separate virtual host or a directory served by another application.
  • A proxy or CDN may be the final response layer. Even if Apache adds a header, a cache or reverse proxy can replace, remove, or duplicate it.

If you cannot verify these settings, ask the host to confirm that FileInfo directives are allowed and that mod_headers is active. When the host sets AllowOverride None, move the rule to the virtual-host/server configuration through the administrator rather than trying to force it into WordPress.

Back up and scope the change

  1. Download or copy the current .htaccess file before making edits. Keep a dated, known-good version so a syntax error can be reverted immediately.
  2. Identify the URL path that needs cross-origin access: for example, a REST endpoint, a GraphQL route, JavaScript files, fonts, or images. Put the rule in the document-root file only when the whole site needs the policy; otherwise use the narrower directory that serves those resources.
  3. Inspect the current response first. WordPress core, a plugin, application code, a CDN, or another Apache context may already add CORS headers. Adding a second policy can create duplicate Access-Control-Allow-Origin values that browsers reject.

Keep the smallest possible origin, method, header, and resource scope. MDN’s CORS guidance recommends allowing the minimum number of origins and resources required for the site to function.

Allow a public, non-credentialed resource

For a genuinely public asset or API that does not use cookies, HTTP authentication, or other credentials, a wildcard is the simplest policy:

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

Header always set is useful when you want the header on error responses as well as successful responses. The <IfModule> wrapper prevents an unknown-module error, but it also means the rule silently does nothing when mod_headers is absent; confirm the module rather than treating a missing header as proof that the browser is at fault.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Do not apply this rule indiscriminately to every WordPress response. A site-wide wildcard can expose responses that were intended for same-origin pages, and it does not make a private endpoint safe. Limit it to the API or asset directory whenever possible.

Allow one private frontend origin

For a known application frontend, return its exact origin:

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

Replace the example with the real scheme, hostname, and port. Do not write https://app.example.com/, add a URL path, or list several origins separated by commas; the response header accepts one origin value or the wildcard.

Vary: Origin tells shared caches that the representation can differ according to the request’s Origin header. It is required whenever the server selects an explicit origin dynamically and is a prudent cache signal for policies that may vary by origin.

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.

Support several origins safely

Apache cannot safely authorize several private origins by blindly reflecting whatever value the browser sends. If production, staging, and a partner application are all legitimate clients, compare the incoming Origin against a fixed allowlist and emit a single matching value.

The comparison can be implemented in Apache server configuration, WordPress code, or the application that owns the endpoint. The important properties are:

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
  • The allowlist is fixed and reviewed; arbitrary input is never copied into Access-Control-Allow-Origin.
  • Only one approved origin is emitted for each response.
  • Vary: Origin is sent because the response changes according to the request origin.
  • An unapproved origin receives no allow-origin header (or an intentional denial), rather than being reflected.

When the host does not permit the needed conditional directives in .htaccess, put this logic in the virtual-host configuration or WordPress endpoint code. A static rule is preferable to a complex workaround that is difficult to audit.

Handle preflight OPTIONS requests

Browsers send a preflight OPTIONS request before many cross-origin requests, especially when the method is not a simple method or the request includes headers such as Authorization. The preflight asks whether the actual method and request headers are allowed.

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

Add only the values the application really uses:

<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>

The example permits GET, POST, and OPTIONS, and allows the two named request headers. Do not copy this list unchanged if the endpoint accepts fewer methods or does not send an authorization header. Match the browser’s requested method and header names; otherwise the preflight can fail even though the main response looks correct.

These headers do not replace Access-Control-Allow-Origin. The preflight response needs an origin that matches the frontend’s origin, along with any required method and header permissions. Ensure that the server returns a usable status for OPTIONS instead of redirecting it to a login page or a trailing-slash URL.

Configure credentialed requests correctly

Cookies, HTTP authentication, and explicitly credentialed fetch requests require a specific origin. They cannot be used with Access-Control-Allow-Origin: *. Browsers reject a wildcard when credentials are included.

Use an exact origin and explicitly authorize credentials:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "https://app.example.com"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Vary "Origin"
</IfModule>

The frontend must also opt in to credentials (for example, a Fetch request with credentials: "include"), and the server must set cookie attributes appropriate for the deployment. CORS does not bypass WordPress login checks, nonce validation, capability checks, or API authentication. A permissive CORS rule only determines whether browser JavaScript can read a response after the server has processed the request.

Do not use Access-Control-Allow-Origin: null as a workaround. A hostile document can obtain a null origin, so treating it as trusted weakens the boundary.

Understand WordPress’s own CORS behavior

WordPress includes send_origin_headers(), which handles OPTIONS requests and can send access-control headers for an allowed origin or return a 403 response when the origin is not allowed. A plugin, theme, or custom REST endpoint may also add its own headers.

Inspect the final response before adding Apache directives. If WordPress already emits the correct policy, changing .htaccess may create duplicate values. If the WordPress layer intentionally denies an origin, an Apache rule that adds a broad header can produce a misleading response and expose an endpoint that the application meant to restrict.

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

Choose one authoritative layer for the policy whenever possible. Apache is useful for static assets or a host-wide baseline; endpoint code is usually better when authorization depends on the current user, route, or tenant.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the response, not just the configuration file

Use browser developer tools or an HTTP client against the real public URL. Test both the preflight and the actual request, and follow redirects because a redirect response can lack the required headers.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
  1. Open the browser’s Network panel and reproduce the failing request. Select the OPTIONS entry, if present, and record its status and response headers.
  2. Confirm that Access-Control-Allow-Origin contains exactly the requesting origin—or * for a non-credentialed public request—and appears only once.
  3. For preflighted calls, verify Access-Control-Allow-Methods contains the requested method and Access-Control-Allow-Headers contains every requested non-simple header.
  4. Inspect the actual GET, POST, or other request. The final response also needs the allow-origin header; a successful preflight alone is not enough.
  5. When the response varies by origin, verify Vary: Origin. Check whether a CDN or proxy cached a response generated for a different origin.
  6. Compare responses from an allowed origin, an unapproved origin, and a same-origin request. This reveals accidental reflection and confirms that the rule is scoped as intended.

An HTTP client can send an origin explicitly. For example:

curl -i -H "Origin: https://app.example.com" https://www.example.com/api/endpoint

curl -i -X OPTIONS 
  -H "Origin: https://app.example.com" 
  -H "Access-Control-Request-Method: POST" 
  -H "Access-Control-Request-Headers: Content-Type, Authorization" 
  https://www.example.com/api/endpoint

Replace the URL and requested method or headers with those used by your application. The command shows headers returned by the server; it does not emulate every browser credential rule.

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

Fix common failures

500 Internal Server Error

A 500 immediately after editing usually means Apache rejected a directive. The host may disallow the FileInfo override class, the directive may be unavailable because mod_headers is not loaded, or the file may contain a syntax error. Restore the backup, then ask the administrator to enable the directive or place the rule in server configuration.

The rule has no effect

The file may be ignored because AllowOverride None is active, may be in a directory that does not serve the requested resource, or may be overridden by a proxy/CDN. Confirm which server generated the final response and test the exact endpoint rather than a different WordPress page.

Duplicate or conflicting allow-origin headers

Search the response chain for headers added by WordPress, a security or cache plugin, application code, another Apache context, and the CDN. Remove all but the intended policy. Browsers need one coherent allow-origin value; two different values are not merged into a valid permission.

Preflight still fails

Read the OPTIONS response. Check its status, redirects, allow-origin value, allowed method, and allowed request headers. Add only the missing method or header and ensure the spelling matches the browser’s Access-Control-Request-Headers value. A login redirect, firewall challenge, or 403 on OPTIONS must be fixed at that layer.

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

Credentials are rejected

Replace * with the exact frontend origin, send Access-Control-Allow-Credentials: true, and make the browser request credentialed. Verify that the endpoint’s authentication and cookie settings permit the cross-origin deployment.

A cache returns the wrong origin

If different callers receive different allow-origin values, send Vary: Origin and configure the cache to respect it. Purge an already-cached response after changing the policy.

The API is on another server

A local WordPress .htaccess file cannot add headers to a remote API response. The server that owns that API must configure CORS, or your architecture must route requests through a server you control. A browser extension or local development proxy may hide the issue during testing but does not fix production behavior.

Choose the right configuration layer

Layer Best use Key limitation
Apache .htaccess Simple, directory-scoped policies for assets or an endpoint when the host permits FileInfo. Unavailable or restricted on some hosts; can conflict with application and cache headers.
Apache virtual-host/server configuration Central policies, conditional origin selection, and environments where overrides are disabled. Requires administrator access and careful configuration reloads.
WordPress/plugin or endpoint code Policies that depend on route, user, tenant, or application allowlists. Must handle every response path, including errors and OPTIONS.
CDN or reverse proxy Policies applied at the edge, with cache behavior controlled alongside headers. Can mask origin-server changes and introduce duplicate or stale headers.

Security rules to keep in place

  • Allow the minimum origins and resources necessary for the feature.
  • Use * only for public, non-credentialed responses.
  • Use an exact origin plus Access-Control-Allow-Credentials: true for cookie- or authentication-based browser requests.
  • Never reflect an arbitrary Origin header and never trust null as a shortcut.
  • Keep WordPress permissions, nonces, authentication, rate limits, and authorization checks independent of CORS.
  • Review preflight methods and headers whenever the frontend changes; a broad permanent list makes future mistakes harder to detect.

A practical deployment sequence

  1. Record the failing URL, requesting origin, method, credentials mode, and browser error.
  2. Inspect the existing OPTIONS and actual responses for current CORS headers and duplicates.
  3. Confirm AllowOverride/AllowOverrideList and mod_headers with the administrator.
  4. Back up .htaccess and add the narrowest rule in the directory serving the resource.
  5. Choose a wildcard only for public anonymous access; otherwise use an exact origin and add credential or preflight headers only when required.
  6. Test allowed, denied, preflight, redirect, error, and cached responses.
  7. Remove conflicting headers at WordPress, plugin, CDN, or Apache layers and document the final owner of 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 *

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.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.