2

I'm hosting my rails app with heroku and managing my DNS with ZerigoDNS (the free heroku addon). I use Amazon S3 to store all of my assets.

I have a public folder in my S3 bucket called newsletter. I'd like http://mydomain.com/newsletter to simply act as an alias to https://my-bucket.s3.amazonaws.com/newsletter.

How would I go about doing that?

Thanks!


Edit: preferably, I'd like the URL to not redirect but instead just read from the S3 folder. So I'd basically just set up an alias for https://my-bucket.s3.amazonaws.com/newsletter. Is there a way to do that using routes.rb or some gem?

Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
  • 1
    This answer may be useful for you: http://stackoverflow.com/questions/3622706/creating-a-rails-route-to-an-external-url – Blue Smith Sep 16 '12 at 18:03
  • Thanks @BlueSmith, but it looks like this does an actual redirect. Will urls such as `http://mydomain.com/newsletter/september/12/main.jpg` still work if they don't exist on the server but are instead redirected to S3? Also, even if they do, would that be something that spam filters wouldn't like because they'll notice a redirect in an img tag `'? Thanks! – Yuval Karmi Sep 16 '12 at 18:20
  • Well, if you don't want to redirect, you can write an action controller to read data from S3, then send data back from your action controller. But the performance may not very good. – Blue Smith Sep 16 '12 at 18:25
  • Is there a way to do that with rewrites instead of passing the data through the application? There's no point in using sendfile here or the likes, I'm dealing with public data that needs zero server processing aside from serving it. – Yuval Karmi Sep 16 '12 at 19:08
  • You can configure your bucket to respond to a subdomain of your choosing: so your images can be served from e.g. `http://media.mydomain.com/newsletter/x/y/main.jpg`. If ou're worried about spam filters, they may be happier about this. Otherwise, no. You can't serve files from a particular domain without serving them from that domain. – canton7 Sep 16 '12 at 23:12

0 Answers0