1

I want to rewrite all my JPG file URLs using mobify CDN. For that, all I have to do is prepend the URL

https://ir0.mobify.com/jpg50/ to my existing URL. So for example, if I have the URL

http://xxx.yyy.com/wp-content/uploads/2290/07/abc.png then the user has to be redirected to

https://ir0.mobify.com/jpg50/http://xxx.yyy.com/wp-content/uploads/2290/07/abc.jpg

I wrote the following code in my nginx config. I tested the regexs at regexlib and they seem to be fine.Still do not understand what is wrong with my config. Please help.

location ~ \.jpg$ { rewrite ^http://(.*).jpg$ https://ir0.mobify.com/jpg50/$uri last; }

1 Answers1

0

Try this ...

location ~ \.jpg$ { 
    return 301 https://ir0.mobify.com/jpg50$request_uri; 
}
Dayo
  • 12,413
  • 5
  • 52
  • 67
  • Well, that looks like it should do the trick. But, doing this via nginx sends the URL into a redirect loop. That happens as when mobify has not cached the image_(first time access by any user for a given file)_, it tries to fetch it directly from the server and when it tries to do that, it is automatically redirected to the prepended URL and hence the redirect loop. So, I guess it would be better to handle this at the application layer. if you have any solution to this redirect-loop problem, please share. –  Sep 21 '14 at 08:11
  • You will have to send a cookie or header from Mobify to Nginx and test on this before redirecting. – Dayo Sep 21 '14 at 12:24
  • Well, mobify is beyond my control so I guess will have to handle it at the application layer –  Sep 22 '14 at 10:00