CDN Rewrites
After releasing a WordPress plugin called Free CDN, I got a request from Mike Colburn to somehow extend my plugin so that rewriting hosts for commerical CDNs – those big names like Limelight, Akamai, Velocix, EdgeCast etc is supported. I am so lucky that Mike is an expert with CDNs – he even works for one of the biggest companies of the field – so with the great help from him, I’ve managed to implement this new plugin called CDN Rewrites, as I feel for Free CDN it’s a little out of scope.
Basically, CDN Rewrites allows a WordPress user to specify two important variables: an orgin host (says http://www.yoursite.com) and a “destination host” (like http://www.static.yoursite.com). It will then find all the static contents from that orgin host and rewrite them into the destination so that they will be delivered from there. For example, http://www.yoursite.com/wp-content/uploads/a-big-image.png may be rewritten into http://www.static.yoursite.com/wp-content/uploads/a-big-image.png or http://www.images.yoursite.com/a-big-image.png depending on your settings.
Because of the way it works, this plugin may cover Free CDN’s main feature too: you can rewrite http://www.yoursite.com into http://www.yoursite.com.nyud.net to make use of Coral CDN without having Free CDN installed.
Features
- Multiple profiles are supported, allowing different contents to be treated differently
- You can exclusively select the content types for each profile – currently supporting JS, CSS, images, inline background images, and <object>’s
- Additional URL’s can be added as excludes
- Debug mode gives you a good preview to make sure nothing goes wrong
- Works normally with other plugins. Especially useful if run along with WP Super Cache
- AJAX’ed admin section makes it quick and easy to adjust the settings
Installation and Documentation
- Download the plugin
- Extract into a folder
- Upload the entire to `wp-content/plugins/` directory of your WordPress installation
- Enable it via Plugins panel
- Head to Settings->CDN Rewrites and create the first profile.
- You’re ready to go!
FAQ and History
Head to plugin Codex page.
Download
There’s no demo yet – I don’t use commerical CDN personally and understandably ![]()
Download
Download the latest brain dumps and pass your JN0-350 as well as 650-195 certification exam in first attempt guaranteed.


roger
29 Sep, 2009
wow this is big treat for us i used your previous plugin free cdn work great i hope even this work very well thank you so much
Martin
14 Oct, 2009
Thanks for the plugin. Found a minor bug though. If the theme doesn’t call wp_footer it doesn’t work.
phoenix.heart
14 Oct, 2009
Martin, it’s not a bug. Calling wp_footer or wp_header is required for almost every plugin, as the functions trigger the plugin actions.
If a theme doesn’t call wp_footer or wp_header, then I can tell you it’s a sucking theme.
Mike
14 Oct, 2009
You can see this plug in work without actually having a CDN.
Setup an A-Record for your domain like images.domain.com
Then use the plugin to rewrite all your images to be images.domain.com
You can right click on one of the images and see the source URL. Assuming you have a CDN, you could CNAME images.domain.com and get the same result
- Mike Colburn
Martin
16 Oct, 2009
@phoenix.heart according to the codex: “This hook is theme-dependant which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it.”
So strictly speaking the plugin should account for it.
I think I might have discovered another few bugs.
#1
I suddenly wasn’t able to invoke the media upload dialog – clicking the icon it darkens the screen and then nothing happens. Disabling CDN and it works again.
#2
In the goTop() function in the admin.js file. t is undefined if clearTimeout() is called.
phoenix.heart
16 Oct, 2009
Martin, I agree with you on “strictly speaking”. But strictly speaking too, wp_header and wp_footer are mandatory, since almost all javascript, css includes, and a lot of other tasks are triggered via these two functions. So the themes should take them into account instead of them taking some specific themes IMHO.
About the bugs:
#1. I will certainly check again. However that’s not necessarily mean it’s a CDN Rewrites bug – sometimes it may be a plugin conflict.
#2. This is A BUG! I forgot to declare t as global. Thank you!
Cheers,
An
Martin
16 Oct, 2009
#1, yeah maybe it is a conflict. I mocked around and I think if I removed the CDN jquery files the upload dialog would work again – so maybe there’s a jquery conflict with the WP jquery files !? But I guess if it works for you with WP 2.8.4 it’s more likely to be a plugin conflict…
Artem Russakovskii
17 Jan, 2010
An, did you delete my comment or it’s stuck in moderation?
I filed a few tickets, please check the wordpress plugin page.
phoenix.heart
17 Jan, 2010
Strange enough Artem, I don’t see your comment in either approved, spam, or pending.
I read your tickets on WP forum though, and wanted to says thanks
You’re correct about including the plugin js and css on any admin page, it’s a bad habit as specified by Ozh some time ago. I will definitely keep this in mind for the next version.
For jQuery, thing is my plugin(s) use live() which is only available from 1.3 when earlier WP versions (not sure with 2.9) only come with up to 1.2.x (please correct me if I’m wrong). If there is a way to force WordPress to use 1.3.2↑ I’ll much appreciate.
For CDN Rewrites not working on your site, to admit I don’t have any clue yet. Help me with a bit more details will you?
Artem Russakovskii
17 Jan, 2010
An,
I see your problem with .live(). Well, looks like 2.8 was the first one with 1.3, while 2.7 still had 1.2. You can easily check by looking at svn revisions: http://svn.automattic.com/wordpress/tags/2.8/wp-includes/js/jquery/jquery.js vs http://svn.automattic.com/wordpress/tags/2.7/wp-includes/js/jquery/jquery.js
I think if you specify 2.8 as the min revision for your plugin, you should be able to then use wp_enqueue_script() and load the script correctly.
For the rewrites, I haven’t played with your code yet. I will when I have some free time.
Thanks,
Artem
Peter Bowey
11 Apr, 2010
Great plugin, and works well with WordPress 3.0 beta1
This is one of the few WordPress code tools that actually do understand how to correctly use multiple static assets!
Well done!
Peter Bowey
Q-Zma
15 Apr, 2010
options page not work at all for 2.9.2 neither in latest chrome neither in latest firefox
Q-Zma
15 Apr, 2010
js/admin.js line 126 you try to clear timeout with undefined id t, just cange it:
else if (typeof t != ‘undefined’) { clearTimeout(t); }
and functions in global namespace are evil, yo!
emonweb
18 Apr, 2010
i just wandering how it is effective to setup a self hosted static CDN like mycnd.myhost.com
Mike Colburn
19 Apr, 2010
Emonweb, I don’t understand your question. Are you asking if this will really accelerate your pages?? More details… – Mike
Mike D
3 Aug, 2010
Hi!
I’ve installed your plugin on my site.
Before you ask . . . I do have S3 set up, and have successfully served newly-uploaded images using the Amazon S3 for WordPress plugin. It only uploads as new things are brought in, however. And yes, I disabled it to test yours.
Added a profile, set for images only. It appears to have no effect. No upload dialog box (should there be one?). Images are still served locally.
I understood yours would upload the existing files and rewrite the URLs. Did I misunderstand? Or do something horribly wrong?
Thanks!
phoenix.heart
3 Aug, 2010
Hi Mike, indeed you misunderstood. CDN Rewrites doesn’t upload the files, but instead rewrites your existing file links following your defined pattern. If you’re looking for a plugin that can upload files to a CDN, last time I checked W3 Total Cache has such a feature
Mike Colburn
3 Aug, 2010
Mike D.
Create a CNAME to S3 called images.domain.com or something like that. Now using the Plugin, create an images profile. The Plugin will rewrite the URL for all images to images.domain.com so now all the images will come from the S3. But you still have to publish the content to S3 like you’ve been doing. This plugin does not UPLOAD content anywhere, just rewrites URLs
- Mike