This attempted rewrite rule in my routes.rb is probably self-explanatory:
match "/:user/:photo-thumb.png" =>
redirect("/%{user}/photos/%{photo}/image?style=thumb"),
:photo => /[a-zA-Z]+/
I want to redirect something like mysite.com/alice/foo-thumb.png to mysite.com/alice/photos/foo/image?style=thumb
The above attempt is wrong though. Any ideas for fixing it?
The following worked for me:
match "/:user/:photo_thumb.png" =>
redirect{|p|
"/#{p[:user]}/photos/#{p[:photo_thumb].split('-')[0]}/image?style=thumb"
},
:constraints => { :photo_thumb => /[a-zA-Z]*\-thumb/ }
I'd love to find a simpler way to do it though. (As tadman points out, I may be better off doing this with nginx rewrites. See this related question: Routes.rb vs rack-rewrite vs nginx/apache rewrite rules )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With