Skip to main content
KadiCache
Browse 37 Docs Guides & Search

Custom Pull-CDN CNAME Rewriting, Font CORS, Varnish Purge & Proxy Trust

Rewrite static assets to BunnyCDN, CloudFront, or KeyCDN with 1-click Font CORS rules, synchronize Varnish reverse-proxy PURGE requests, and configure Trusted Proxy IPs.

Optimization/CdnUrlRewriter.phpIntegrations/Cdn/CdnUrl.phpIntegrations/Proxy/VarnishPurge.phpCache/Policy/TrustedProxy.php
WP Admin -> KadiCache -> CDN & Varnish
MODULE 32 · 2X RETINA
Pull-zone CDN asset rewriting, Font CORS verification, and all Varnish reverse-proxy settings unified in CDN & Varnish.2880×1840 WebP
Quick Summary · 30-Second Operational SpecSource-Verified Guide
WP Admin Path
WP Admin -> KadiCache -> CDN & Tools -> Proxy, 404 & Hints
Expected Outcome
5 Per-Asset-Type Toggles · 1-Click Font CORS Rules · Varnish VCL 4.1 Sync
Key Marker / Engine
CdnUrlRewriter.php | VarnishPurge.php | TrustedProxy.php
  • Pull-Zone CDN Rewriter (CdnUrlRewriter.php + CdnUrl.php): Rewrites static asset URLs across HTML, srcset, inline style attributes (CSP-validated), and generated CSS to your HTTPS CDN CNAME (BunnyCDN, CloudFront, KeyCDN, Fastly).
  • 5 Granular Asset-Type Toggles & Exclusions: Independently toggle Images, CSS, JavaScript, Fonts, and Media (cdn_images, cdn_css, cdn_js, cdn_fonts, cdn_media) with live URL preview and Font CORS verification.
  • Varnish Reverse-Proxy Bridge (VarnishPurge.php + VarnishDiscovery.php): Synchronizes targeted PURGE and full-site regex bans (X-Purge-Method / Proxy Cache Purge VCL 4.1 contract) with automatic retry locks.
  • Trusted Proxy & s-maxage Governance (TrustedProxy.php): Validates X-Forwarded-For / X-Forwarded-Proto strictly from trusted proxy CIDRs so spoofed client headers never poison cache scheme buckets.

When to Use a Custom Pull-Zone CDN CNAME (vs DNS Proxy CDNs)#

While Cloudflare proxies your entire root domain (example.com) at the DNS layer, pull-zone CDNs—such as BunnyCDN, Amazon CloudFront, Google Cloud CDN, KeyCDN, and Gcore—give you a dedicated static-asset hostname like https://cdn.example.com that pulls static files from your WordPress origin on first request and caches them worldwide.

KadiCache Free Core (CdnUrlRewriter.php and CdnUrl.php) rewrites your static asset URLs cleanly inside WP Admin -> KadiCache -> CDN with zero database search-and-replace mutations: turning the toggle OFF restores origin URLs immediately.

FIG 01Configuring HTTPS CDN CNAME URL, viewing live asset rewrite preview, checking Font CORS status, and syncing Varnish PURGE inside WP Admin -> KadiCache -> CDNZoom 2x

Configuring Pull-CDN Asset Rules & Preventing Font CORS Errors#

Inside WP Admin -> KadiCache -> CDN, paste your HTTPS CDN hostname (e.g. https://cdn.example.com) and click Asset Rules & CORS to fine-tune exactly which file families route through your CDN:

Asset ToggleSetting KeyDefaultWhat CdnUrlRewriter.php Rewrites
Imagescdn_imagesON<img>, <picture><source>, responsive srcset lists, and CSS url(...) images (.webp, .jpg, .png, .svg, .avif)
CSS Stylesheetscdn_cssON<link rel="stylesheet"> and wp-content/kadicache-assets/css/* files
JavaScriptcdn_jsON<script src="..."> and wp-content/kadicache-assets/js/* files (automatically skipping scripts carrying integrity="..." SRI hashes if needed)
Webfontscdn_fontsON (with CORS check).woff2, .woff, and .ttf typography assets + automatic ResourceHints CDN preconnect!
Video & Audio Mediacdn_mediaONSelf-hosted .mp4, .webm, .mp3 media URLs
FIG 02Copying 1-click Nginx and Apache .htaccess Access-Control-Allow-Origin snippets for CDN-served WOFF2 fontsZoom 2x

Solving Cross-Origin Webfont Blocks (Access-Control-Allow-Origin) in 10 Seconds#

Browsers block .woff2 fonts loaded from https://cdn.example.com on https://example.com unless the origin server includes an Access-Control-Allow-Origin response header before the pull-CDN caches the font! Inside CDN -> Asset Rules & CORS, KadiCache probes your font headers live and provides copy-paste Nginx and Apache .htaccess snippets:

NGINXNginx Font CORS Header Snippet (Served to Your Pull-CDN)
location ~* \.(?:woff2|woff|ttf|otf)$ {
    add_header Access-Control-Allow-Origin "*";
    expires 365d;
    add_header Cache-Control "public, max-age=31536000, immutable";
}

Varnish VCL 4.1 Synchronization (VarnishPurge.php & VarnishDiscovery.php)#

On Cloudways, custom VPS stacks, and enterprise Kubernetes deployments running Varnish Cache (127.0.0.1:6081 or an internal Docker service IP) in front of Nginx/Apache:

  1. Automatic Discovery & Proxy Cache Purge Compatibility (VarnishDiscovery.php): Detects local Varnish listeners and coexists cleanly if the Proxy Cache Purge plugin is present (VarnishPurge::proxyCachePurgeActive()) without sending duplicate content purges.
  2. Custom Varnish Address & Protocol Split (Tools -> Proxy, 404 & Hints): Configure varnish_enabled, varnish_address (e.g. http://127.0.0.1:6081), varnish_split_proto (X-Forwarded-Proto: https + http dual invalidation), and varnish_query_regex matching standard Varnish 4.1+ PURGE VCL (X-Purge-Method: default | regex).
  3. Percent-Encoding Normalization & Retry Queue: VarnishPurge::uppercaseEscapes() purges both lowercase and uppercase percent-escaped Unicode paths (essential for Arabic/non-ASCII slugs!) and queues automatic Action Scheduler retries (kadicache_varnish_retry) if a Varnish node is briefly restarting.

Reverse Proxy Trust & Shared s-maxage Edge Headers (TrustedProxy.php)#

Open WP Admin -> KadiCache -> Tools -> Proxy, 404 & Hints whenever WordPress sits behind AWS ALB, Traefik, HAProxy, Varnish, or Nginx reverse proxies:

  • Proxy Mode (proxy_mode): Prevents attackers from sending fake X-Forwarded-Proto: http headers directly to your server to poison HTTPS cache links (TrustedProxy.php honors forwarded headers only from verified proxy configurations).
  • Shared Edge Cache s-maxage (edge_cache_s_maxage): Optionally emits s-maxage=<seconds> on eligible guest HTML responses while keeping authenticated, cart, and nonce-capped pages strictly private.

Provider-Specific Quick Setup: BunnyCDN, CloudFront & KeyCDN#

Use these provider-specific origin settings when creating your pull zone so KadiCache asset rewriting, gzip/Brotli compression, and font CORS work cleanly from minute one:

  1. BunnyCDN Pull Zone (https://cdn.example.com): Enable Forward Host Header (off by default unless required by multi-tenant Nginx), turn ON Cache-Control origin header respect (Origin Cache Control), and enable CORS Headers (woff2, woff, ttf, css) inside BunnyCDN -> Headers as a belt-and-suspenders backup alongside KadiCache’s origin snippet.
  2. Amazon CloudFront Distribution: Set Origin Protocol Policy to HTTPS Only, attach AWS’s managed CachingOptimized cache policy + CORS-With-Preflight response headers policy on /wp-content/*, and leave /wp-admin/* and /wp-json/* strictly on your main origin domain.
  3. Varnish VCL 4.1 ACL Check (acl purge): Confirm your Varnish VCL acl purge list includes 127.0.0.1 / ::1 (or your PHP-FPM container subnet in Docker/Kubernetes) so VarnishTransportClient.php receives 200 Purged on every PURGE request, and leave varnish_split_proto enabled whenever TLS terminates ahead of Varnish so both HTTP and HTTPS cache entries clear together.

Frequently Asked Operational Questions

Can I use BunnyCDN for static files AND Cloudflare for DNS/WAF at the same time?
Yes! Many high-traffic stores run DNS/WAF through Cloudflare while serving /wp-content/uploads/ media through a BunnyCDN CNAME (https://b-cdn.example.com) configured in WP Admin -> KadiCache -> CDN.
Does CdnUrlRewriter modify my WordPress database post_content URLs?
Never. CdnUrlRewriter rewrites static asset URLs on the fly when building the cached HTML snapshot—your database post_content stays 100% clean with original domain URLs.
How do I exclude one specific plugin file (like a dynamic captcha or service-worker.js) from CDN rewriting?
Add `/service-worker.js` or `/wp-content/plugins/custom-widget/*` inside CDN Exclusions (`cdn_exclusions`), one path fragment per line.
Does CdnUrlRewriter respect strict Content-Security-Policy (CSP) inline style rules?
Yes! Line 82 of CdnUrlRewriter.php checks CspPolicy::allowsInline() before rewriting inline style="background-image:..." attributes so strict hash/nonce CSP policies never break.
What if my Varnish server runs on a custom internal IP like 10.0.0.15:8080?
Open WP Admin -> KadiCache -> Tools -> Proxy, 404 & Hints, enable Varnish Purge, and set Varnish Address to http://10.0.0.15:8080.
Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin/src/Optimization/CdnUrlRewriter.phpapps/wordpress-plugin/src/Integrations/Cdn/CdnUrl.phpapps/wordpress-plugin/src/Integrations/Proxy/VarnishPurge.phpapps/wordpress-plugin/src/Cache/Policy/TrustedProxy.php
Was this engineering guide helpful?