---
title: CDN Serving Dynamic PHP Pages
date: 2013-08-12 09:01:05
permalink: https://lesterchan.net/blog/2013/08/12/cdn-serving-dynamic-php-pages/
author: Lester Chan
excerpt: "Mark Jaquith's presentation, Confident Commits, Delightful Deploys, raised something I hadn't considered: a CDN can proxy everything, including dynamic PHP pages. He pointed to cdn.wpengine.com, cdn.page.ly, and cdn.zippykid.com, each serving the same content as their non-CDN counterparts."
categories:
  - Programming
tags:
  - CDN
  - EdgeRules
  - Mark Jaquith
  - NetDNA
  - WordPress
---

[Mark Jaquith](https://markjaquith.com/)‘s presentation on [Confident Commits, Delightful Deploys](https://wordpress.tv/2013/07/28/mark-jaquith-confident-commits-delightful-deploys-2/) brought up something which I didn’t thought of, “CDN proxies everything including dynamic php pages”.

In his example, he pointed out [cdn.wpengine.com](https://wpengine.com/) and [wpengine.com](https://wpengine.com/), cdn.page.ly and [page.ly](https://pagely.com/), cdn.zippykid.com and [zippykid.com](https://pressable.com/) are all serving the same content with their CDN counterpart.

So out of curiosity, I tested mine, cdn.lesterchan.net and lesterchan.net, and I have the same problem! *I did not link it because I have already fixed the problem before writing this blog post.*

A common link between us are our CDNs are hosted by NetDNA. So I wrote to them asking is there anywhere I can solve this. They recommended me their EdgeRules add-on which provides a powerful method of controlling how edge servers interact with content and websites visitors.

I gave it a try and it works! What I did was to only allow URI with file extensions to be served by the CDN as shown in the screenshot below:

[![EdgeRules](https://farm6.staticflickr.com/5454/9447921543_c6770bf19c_c.jpg "EdgeRules")](https://farm6.staticflickr.com/5454/9447921543_1cd0d11dce_o.png "EdgeRules")

```nginx

Match Type: Default
Directive: REWRITE RULE ^(.*)$ https://lesterchan.net$1 permanent
Conditional: $uri != RegEx (Case In-Sensitive) .(png|jpe?g|gif|ico|html|txt|css|js)$
Rule Status: Active
Purge All Files: Yes

```

[![EdgeRules Main Page](https://farm4.staticflickr.com/3803/9507562710_c1e5239291_c.jpg "EdgeRules Main Page")](https://farm4.staticflickr.com/3803/9507562710_7aa1a964d3_o.png "EdgeRules Main Page")

It is a bit “hack-ish” but I guess it will do for now.

A proper way which Mark Jaquith mentioned was to CNAME the CDN to something like static.yourdomain.com and have that subdomain serve only static files.