如何在heroku上重定向域名? [英] How do I redirect domains on heroku?
问题描述
我为stuff.heroku.com上的多个用户设计了一款应用程序。
I have an app designed for multiple users on stuff.heroku.com
着陆页可能类似stuff.heroku.com/controller/1/action/ 73
A landing page might look like stuff.heroku.com/controller/1/action/73
但是我想要在那里重定向的URL看起来像sub.domain.com/hello
But the URL that I want to redirect there looks like sub.domain.com/hello
,我可能希望sub.domain.com/greetings指向另一个登录页面,这次是stuff.heroku.com/controller/1/action/74。
Similarly, I may want sub.domain.com/greetings to point to another landing page, this time at stuff.heroku.com/controller/1/action/74.
一旦这个工作,我会希望sub.anotherdomain.com/hello映射回我的同一个应用程序,如stuff.heroku.com/controller/1/action/87
Once that works, I will want sub.anotherdomain.com/hello to map back to my same application, such as stuff.heroku.com/controller/1/action/87
我该怎么做?
推荐答案
您可以在application_controller中执行此操作,并在那里重定向。
You can do this in your application_controller and redirect there.
在Rails 2.3+中,您可以使用机架中间件。检查折射宝石 - 它被设置为mod_rewrite的机架替换品
In Rails 2.3+ you can use rack middleware. Check out the Refraction gem -- it's setup to be a rack replacement for 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重写。
The above will just take people from stuff.heroku.com to sub.domain.com -- but you could easily do your /hello rewrite if you want.
这篇关于如何在heroku上重定向域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!