如何在heroku上重定向域?

时间:2011-02-18 18:25:52

标签: ruby-on-rails redirect heroku

我在stuff.heroku.com上为多个用户设计了一款应用

目标网页可能看起来像stuff.heroku.com/controller/1/action/73

但我要重定向的网址看起来像sub.domain.com/hello

同样,我可能希望sub.domain.com/greetings指向另一个目标网页,这次是在stuff.heroku.com/controller/1/action/74。

一旦有效,我会希望sub.anotherdomain.com/hello映射回我的同一个应用程序,例如stuff.heroku.com/controller/1/action/87

我该怎么做?

1 个答案:

答案 0 :(得分:2)

您可以在application_controller中执行此操作并在那里重定向。

在Rails 2.3+中,您可以使用机架中间件。查看折射宝石 - 它的设置是mod_rewrite

的机架替代品

https://github.com/pivotal/refraction

Refraction.configure do |request|
  if req.host == 'sub.domain.com'
    req.rewrite! "http://sub.domain.com/#{req.path}"
  end
end

以上只会将人们从stuff.heroku.com带到sub.domain.com - 但如果你愿意,你可以轻松地进行/ hello重写。