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.
- Pull-Zone CDN Rewriter (
CdnUrlRewriter.php+CdnUrl.php): Rewrites static asset URLs across HTML,srcset, inlinestyleattributes (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, andMedia(cdn_images,cdn_css,cdn_js,cdn_fonts,cdn_media) with live URL preview and FontCORSverification. - Varnish Reverse-Proxy Bridge (
VarnishPurge.php+VarnishDiscovery.php): Synchronizes targetedPURGEand full-site regex bans (X-Purge-Method/ Proxy Cache Purge VCL 4.1 contract) with automatic retry locks. - Trusted Proxy &
s-maxageGovernance (TrustedProxy.php): ValidatesX-Forwarded-For/X-Forwarded-Protostrictly 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.
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 Toggle | Setting Key | Default | What CdnUrlRewriter.php Rewrites |
|---|---|---|---|
| Images | cdn_images | ON | <img>, <picture><source>, responsive srcset lists, and CSS url(...) images (.webp, .jpg, .png, .svg, .avif) |
| CSS Stylesheets | cdn_css | ON | <link rel="stylesheet"> and wp-content/kadicache-assets/css/* files |
| JavaScript | cdn_js | ON | <script src="..."> and wp-content/kadicache-assets/js/* files (automatically skipping scripts carrying integrity="..." SRI hashes if needed) |
| Webfonts | cdn_fonts | ON (with CORS check) | .woff2, .woff, and .ttf typography assets + automatic ResourceHints CDN preconnect! |
| Video & Audio Media | cdn_media | ON | Self-hosted .mp4, .webm, .mp3 media URLs |
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:
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:
- 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. - Custom Varnish Address & Protocol Split (
Tools -> Proxy, 404 & Hints): Configurevarnish_enabled,varnish_address(e.g.http://127.0.0.1:6081),varnish_split_proto(X-Forwarded-Proto: https+httpdual invalidation), andvarnish_query_regexmatching standard Varnish 4.1+PURGEVCL (X-Purge-Method: default | regex). - 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 fakeX-Forwarded-Proto: httpheaders directly to your server to poison HTTPS cache links (TrustedProxy.phphonors forwarded headers only from verified proxy configurations). - Shared Edge Cache
s-maxage(edge_cache_s_maxage): Optionally emitss-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:
- BunnyCDN Pull Zone (
https://cdn.example.com): Enable Forward Host Header (off by default unless required by multi-tenant Nginx), turn ONCache-Controlorigin header respect (Origin Cache Control), and enable CORS Headers (woff2,woff,ttf,css) inside BunnyCDN ->Headersas a belt-and-suspenders backup alongside KadiCache’s origin snippet. - Amazon CloudFront Distribution: Set Origin Protocol Policy to
HTTPS Only, attach AWS’s managedCachingOptimizedcache policy +CORS-With-Preflightresponse headers policy on/wp-content/*, and leave/wp-admin/*and/wp-json/*strictly on your main origin domain. - Varnish VCL 4.1 ACL Check (
acl purge): Confirm your Varnish VCLacl purgelist includes127.0.0.1/::1(or your PHP-FPM container subnet in Docker/Kubernetes) soVarnishTransportClient.phpreceives200 Purgedon everyPURGErequest, and leavevarnish_split_protoenabled 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?
Does CdnUrlRewriter modify my WordPress database post_content URLs?
How do I exclude one specific plugin file (like a dynamic captcha or service-worker.js) from CDN rewriting?
Does CdnUrlRewriter respect strict Content-Security-Policy (CSP) inline style rules?
What if my Varnish server runs on a custom internal IP like 10.0.0.15:8080?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.