开发者

There is any way to configure Rails so it uses another public location for different domains?

开发者 https://www.devze.com 2023-04-10 22:59 出处:网络
I have the following folder structure: /rails /public /images And I have 2 domains: long_domain.com short.one

I have the following folder structure:

/rails
  /public
    /images

And I have 2 domains: long_domain.com short.one

I want that when long_domain.com is loaded it uses the /public folder as public, and when short.one is loaded it uses the /public/images

The problem is that I don't want it to load the routes, it should act as the original public folder.

开发者_如何学GoCan this be done with Rails? Would it be better to use another "static" and lightweight server?


There's a few ways you could do this.

If you have your images hosted offsite, you'll have to use full URLs in your image tags. Relative links would go to your CDN or site where your images are. The advantage here is that you have explicit control over your app and it's likely to work. I'd define some constant in my config for the image hosting location so I could easily change it later.

Outside of that, you could use mod_passenger to proxy back to Rails and use a mod_rewrite rule to rewrite your image tags on the fly. The advantage here is that you wouldn't have to change your app (although the changes probably aren't too bad). The problem is that mod_rewrite is regex's so it might take some playing to figure out the right rule (and testing all the weird cases).

A third option is to use a gem. If you are really trying to scale out your image handling, you should just switch to Dragonfly which can store a secondary copy of the image anywhere you want. It has lots of options and features. It sounds like you would be interested in this aspect of it: http://markevans.github.com/dragonfly/file.DataStorage.html

Hope this gives you some ideas.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号