Forum Moderators: phranque

Message Too Old, No Replies

Redirect certain images to CDN

how to redirect images to a cdn

         

hans121

9:12 am on Apr 23, 2012 (gmt 0)

10+ Year Member



Hi,

I have recently moved my jpg images to a content delivery network (CDN). The cdn pulls the images via the domain origin.mysite.com and serves via cdn.mysite.com
The old image locations are something like:
www.mysite.com/images/pic.jpg
the new ones are
cdn.mysite.com/images/pic.jpg

I've just changed the filepaths in my html and php files to target the files on the cdn.

I thought it might be a good idea to rewrite old images to the new location.
Tried the following:

<FilesMatch "\.jpg$">
Header set Cache-Control "must-revalidate, max-age=2592000"

RewriteCond %{HTTP_HOST} !^origin\.mysite\.com
RewriteCond %{REQUEST_URI} !(file1|file2|file3).jpg$
RewriteRule ^(.*)$ http://cdn.mysite.com/$1 [R=301,L]
</FilesMatch>


My questions:
Why do the rewrite rules only work if they are NOT inside the <FilesMatch>?
Will requests NOT go through the rewrite conditions inside the <FilesMatch> if jpg images are requested? I placed them inside the <FilesMatch> because I assume better performance, is that right?

Without rewriting, my images are accessible via two locations. I'm not sure if this is a SEO issue because it's just images. Does anyone know about that?
Most of my images are indexed in search engines with their old addresses. Will they disappear from the SERPS and get replaced by the new ones because they are no longer linked from my pages (but still available, in case i don't rewrite them)?
Do you think it would affect search engine rankings if I just left them available at both locations?

Thanks in advance!

lucy24

12:57 pm on Apr 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need an envelope. You need a rule that specifies

blahblah.jpg {and then the Rule}

with Conditions as necessary. It will do the same thing you're trying to do.

Usually people say "redirect" when they mean "rewrite". You're doing the opposite :) It's happening through mod_rewrite, but those are bona fide 301 redirects. If all your internal html uses the new correct addresses, then the redirects are only for search engines. And they are much quicker on the uptake when it comes to subsidiary files. One or two 301s and they've got the message.

I don't think you can put anything inside <Files> or <FilesMatch> but core directives like Allow/Deny. But don't quote me; trying to figure it out is liable to leave your brain twisted up like a moebius strip.