Setting up WordPress behind Amazon Cloudfront

Many websites and places that talk about integrating Amazon Cloudfront with WordPress are simply talking about static assets. Using some caching plugin that rewrites the URLs in the page’s source to point at your Cloudfront distribution, and that’s about it. They don’t talk about how your server can be (as WP SuperCache puts it) Stephen Fry-proof. No one actually says anything about how to put YOUR ENTIRE WEBSITE behind Amazon Cloudfront (and by this, I mean pointing your www.* domain at Cloudfront and letting it take care of everything).

How we use Amazon CloudFront for dynamically generated content

There are well documented requirements to the resources Amazon CloudFront will cache. For our use-case most interesting HTTP headers would be the Cache-Control, Date, Last-Modified and ETag.

Amazon CloudFront uses Cache-Control header to control how long it should cache given resource. There is another Expires header available in the HTTP spec, however Cache-Control is preferred by CloudFront.

Apart from that we need to serve Date and Last-Modified headers that are required to compute expire value from Cache-Control header.