rewrite rule to send all static content to CDN?

Joe Shang joe.shang at
Sat Jun 13 03:19:28 MSD 2009

With Apache we can do this using:

RewriteRule .*\.(jpg|gif|png|flv|css|js|swf)$
http://cdn-domain-name/$0   [R=301,L]

But we want our CDN to serve our static content, what would be easier
to accomplish this?

I tried:

rewrite ^/*\.(jpg|gif|png|flv|css|js|swf)$$1 last;

But it didn't work.

Should I be using a location instead?

        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
              access_log        off;
            expires           30d;

Like the above ones? but how would the rewrite portion come into play?



More information about the nginx mailing list