Forum Topic: Rewrite asset requests to CDN
I have a site that is built with ExpressionEngine. There’s currently no plugin for EE that automatically routes requests to the CDN so I can either build my own, hardcode links with the CDN address, or use htaccess. In my mind htaccess would be faster than a plugin anyways as that way I’m not relying on php to process the urls.
What I’ve done is added several rewrites in my htaccess so that any requests for assets will get redirected to the cdn. That sounds good but it doesn’t seem to be working. any ideas, tips, helps?
RedirectMatch subdomain.domain.com/images(.*) cdnaddress.netdna-cdn.com/images$1
RedirectMatch subdomain.domain.com/files(.*) cdnaddress.netdna-cdn.com/files$1
RedirectMatch subdomain.domain.com/css(.*) cdnaddress.netdna-cdn.com/css$1
RedirectMatch subdomain.domain.com/js(.*) cdnaddress.netdna-cdn.com/js$1
2 Replies to “Rewrite asset requests to CDN”
Glad to help, here are some things to check:
- Is the code added on the domain to which you are redirecting, or on the subdomain?
- Is mod_alias enabled on your server?
- Can you get *any* redirects to work?
- Have you tried using mod_rewrite?
- Have you tried adding
http://
to the beginning of the destination paths?
Jeff, thanks for the reply to this, and sorry for the late follow up. I need to check my email because I never saw a notification.
We are using ExpressionEngine which allows me to use variables, so a couple things ended up happening. Since we are using SSL I created a subdomain that is CNAME to the CDN. Then I added that subdomain as a variable and added that to everywhere assets are called on the site.
think that might end up having better performance than htaccess anyways.
thanks again for the reply and I didn’t mean to leave you hanging.