Reputation: 15917
We have upgraded our company website from a static-based system to Ruby on Rails v3.2.
Unfortunately, we still have quite a few requests pouring in for hot-linked static images for '/image/company-logo.png' (and others) but these requests fail with:
Started GET "/images/company-logo.png" for xxx.xxx.xxx.xxx at 2013-12-06 17:07:08 +0000
ActionController::RoutingError (No route matches [GET] "/images/company-logo.png"):
The problem is these requests are filling my logs (I get hundreds per hour).
simply; I need a way to redirect anything for '/images' to '/assets' on Heroku
What I've tried:
get '/images', to: redirect('/assets')
(seems to be ignored, or at least has no effect)
get '/images/:name', to: redirect('/assets/%{name}')
(redirects to /assets, but strips off the '.png', and, so, fails again. There may be other image files/formats too, so I can't effectively hardcode the '.png')
It seems like this would be a fairly common problem, but I cannot find any solutions on the interwebs.
UPDATE
Okay, I've resolved this issue by putting the static images in the public/images folder. I've seen elsewhere that this may be a "bad idea" because of the way Heroku handles static files on multiple dynos, but it seems to work (probably because the images are in the git repo and not being added after-the-fact).
I'd still love to hear any other solutions for mass redirecting assets like this, as I'm not a fan of putting anything in /public, plus it may be useful for those who can't use /public (for various reasons).
~SOLUTION~ (summarized on one line from NARKOZ's answer below)
get '/images/:name.:ext', to: redirect('/assets/%{name}.%{ext}'), constraints: { name: /.+/, ext: /(jpg|png|gif)/ }
Upvotes: 2
Views: 1214
Reputation: 27911
Try:
get '/images/:name.:ext', to: redirect('/assets/%{name}.%{ext}')
Upvotes: 3