I\'m splitting up one of my larger apps and introducing a \'cdn\' url to house common objects like CSS, javascript, and images to avoid duplication. What I need to do, though, i
I've literally just been working on the same thing today and here's what I came up with.
Stick this in your .htaccess file in the root of your site. This obviously relies on Apache and Mod_rewrite.
RewriteEngine on
RewriteBase /
# Redirect content to the CDN
RewriteCond %{HTTP_HOST} !^cdn\.server\.com$ [NC]
RewriteRule .*\.(jpg|gif|png|flv|css|js|swf)$ http://cdn.server.com/$0 [R=301,L]
This will send requests for the file types in the brackets to your cdn and keep requests for other types on your primary server.