BunnyCDN Setup for WordPress (Origin Shield & Query-String Cache)
If you want to speed up your WordPress site globally and reduce server load, BunnyCDN is a reliable, cost-effective CDN solution. However, configuring BunnyCDN properly—especially with origin shield and query-string caching—can be tricky. This guide provides a quick fix and detailed steps to set up BunnyCDN with WordPress, ensuring optimal caching behavior and improved site performance.
Quick Fix: BunnyCDN WordPress Setup with Origin Shield & Query-String Cache
- Create a BunnyCDN Pull Zone pointing to your WordPress origin server.
- Enable Origin Shield in BunnyCDN dashboard to reduce origin hits.
- Configure BunnyCDN to cache query-string parameters correctly.
- Set appropriate cache-control headers in WordPress (via .htaccess or functions.php).
- Update your WordPress URLs to use the BunnyCDN Pull Zone URL.
- Test caching behavior and purge cache when necessary.
Why This Happens
WordPress sites often serve dynamic content with query strings (e.g., ?product_id=123
), which many CDNs do not cache by default or cache incorrectly. Without proper query-string caching, users may get stale or incorrect content. Additionally, frequent origin requests can overload your server, especially during traffic spikes.
BunnyCDN’s Origin Shield acts as an additional caching layer between your origin and the CDN edge nodes, reducing origin load. Properly configuring query-string caching ensures that BunnyCDN caches unique versions of pages based on query parameters, improving cache hit ratio and user experience.
Requirements
- Active BunnyCDN account
- WordPress site with admin access
- Access to your web server configuration (Apache, Nginx, or via cPanel/Plesk)
- Basic knowledge of editing WordPress theme files or .htaccess
Step-by-step BunnyCDN WordPress Setup
1. Create a BunnyCDN Pull Zone
- Log in to your BunnyCDN dashboard.
- Go to Pull Zones and click Add Pull Zone.
- Enter a name (e.g.,
mywpsite
), and set your WordPress site URL as the origin URL. - Click Add Pull Zone and wait for the zone to be created.
2. Enable Origin Shield
- In your Pull Zone settings, navigate to the Origin Shield tab.
- Enable Origin Shield and select the closest region to your origin server.
- Save changes.
3. Configure Query-String Caching
- Go to the Cache tab in your Pull Zone settings.
- Under Query String Caching, select Cache every unique URL.
- Optionally, specify which query parameters to include or exclude.
- Save changes.
4. Set Cache-Control Headers in WordPress
To ensure BunnyCDN caches your content correctly, set proper cache-control headers. You can do this via .htaccess
(Apache) or via WordPress functions.
Apache (.htaccess) example:
# BEGIN BunnyCDN Cache-Control
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 hour"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=3600"
</IfModule>
# END BunnyCDN Cache-Control
WordPress functions.php example:
function add_cache_control_headers() {
if (is_admin()) return;
header('Cache-Control: public, max-age=3600');
}
add_action('send_headers', 'add_cache_control_headers');
5. Replace URLs in WordPress to Use BunnyCDN
Update your WordPress URLs to serve static assets (images, CSS, JS) via BunnyCDN.
- Use a plugin like Better Search Replace to replace URLs in your database from
https://yourdomain.com/wp-content/
tohttps://yourpullzone.b-cdn.net/wp-content/
. - Alternatively, use the WP Rocket or W3 Total Cache plugins to rewrite URLs for static files.
6. Test and Purge Cache
- Visit your site and inspect network requests to verify assets load from BunnyCDN URL.
- Use BunnyCDN’s cache control headers checker or browser dev tools to confirm caching.
- If you update content, purge BunnyCDN cache from the dashboard or via API.
Common Pitfalls
- Not enabling query-string caching: Dynamic pages may serve stale or incorrect content.
- Incorrect cache-control headers: BunnyCDN may not cache content or cache it too long.
- Forgetting to update URLs: Static assets won’t load from BunnyCDN, missing performance benefits.
- Origin Shield region mismatch: Selecting a distant region can increase latency.
- Plugin conflicts: Some caching or security plugins may interfere with headers or CDN URLs.
Works on
Environment | Notes |
---|---|
Apache | Supports .htaccess cache headers and URL rewrites. |
Nginx | Requires manual config for cache-control headers; BunnyCDN works seamlessly. |
LiteSpeed | Compatible with .htaccess and cache headers. |
cPanel / P
Speed & Security
Tags:BunnyCDN, Cache, CDN
|