Redirect from origin server to CDN without causing loop

I want to redirect static files of certain types from my web server to an origin pull CDN. Let’s say the web server URL is, and the original pull CDN URL is I want to redirect documents and images from to without causing redirect loops. I’ve tried on and off for a while to achieve this, but I haven’t been able to do so, even though I’m taking advantage of a header the CDN sends to identify pull requests from it. I was wondering if anyone here might be able to identify where I’m going wrong.

Here’s how I’m trying to do the redirect:

RewriteCond %{HTTP:x-wr-cdn} !level3
RewriteCond %{HTTP_HOST} !^(dev|test)\. [NC]
RewriteCond %{HTTP_USER_AGENT} !^facebookexternalhit.*
RewriteRule ^(.*)\.(pdf|jpg|jpeg|png|gif|doc|docx|ppt|pptx|xls|xlsx|bmp|tff|zip|ico|eot|woff|ttf|epub|mobi|txt)$1.$2 [R=301,L]


Two solutions (from what I see above):

  1. Make cdn’s DocumentRoot the cdn directory under, i.e., NOT the same DirectoryRoot. That way, the redirection to will skip over the’s .htaccess and avoid the redirection.
  2. Simply add another RewriteCond to ensure %{HTTP_HOST} is !^ [NC]



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.