Using WordPress behind a CloudFront Custom Distribution

I’ve been working on this exact same issue. What you need to do is have two domains. One for your backendblog and one that pointing at cloudfront. Your backendblog will be configured to serve up as itself (backendblog). In my test example I’m using my blog as the backendblog.

If this was for production use you would probably have content.example.com as backendblog and www.example.com as cloudfront. Then you setup cloudfront to pull from backendblog (you got this part figured out already) in my example.

The tricky part is to write a plugin that rewrites all your urls from backendblog to the cloudfront url when it’s getting a request with the cloudfront user agent

<?php
/*
Plugin Name: CDN Rewrite
Plugin URI: http://blog.andrewshell.org/cdnrewrite
Description: Rewrite urls on page if behind a CDN
Author: Andrew Shell
Version: 1.0.0
Author URI: http://blog.andrewshell.org/
*/

if (0 == strcmp($_SERVER['HTTP_USER_AGENT'], 'Amazon CloudFront')) {
  $now     = time();
  $expires = strtotime('+1 hour', $now);
  header("Expires: " . gmdate(DATE_RSS,$expires) . "\n");

  add_filter( 'home_url', 'cdnrewrite_url', 100, 4 );
  add_filter( 'site_url', 'cdnrewrite_url', 100, 4 );
}

function cdnrewrite_url( $url, $path, $orig_scheme, $blog_id )
{
  return str_replace('blog.andrewshell.org', 'd11b8ym2xu437t.cloudfront.net', $url);
}

When you want to edit posts and such just log into backendblog, it shouldn’t redirect because it’s configured as backendblog (not the cloudfront url) yet all requests from cloudfront will be corrected so links stay on the CDN domain.

This isn’t perfect, if you look in the source of my cloudfront url you will see a few references to my backendblog, but this is the line of thinking you’ll want to go down. The next step is probably changing the plugin to capture all output in an output buffer and do a str_replace on it before returning it.