我正在尝试使用子域名beta.somedomain.com,我希望它重定向到somedomain.heroku.com/beta
我在这里使用折射宝石:
https://github.com/pivotal/refraction
但我似乎无法让它发挥作用。
尝试:
Refraction.configure do |req|
if req.host == 'beta.somedomain.com'
req.rewrite! "http://beta.somedomain.com/beta/#{req.path}"
end
end
和
Refraction.configure do |req|
if req.host == 'beta.somedomain.com'
req.rewrite! "http://somedomain.heroku.com/beta/#{req.path}"
end
end
也试过
req.permanent! :host => "beta.somedomain.com"
而不是重写
config.middleware.insert_before(::Rack::Lock, ::Refraction)
但两种方法都不起作用,只是将我指向root'/'
答案 0 :(得分:1)
您可以使用Rails 3的内置路由功能:
constraints :subdomain => "beta" do
match "/(:page)" => redirect { |params| "http://somedomain.heroku.com/beta/#{params[:page]}" }
end
查看Rails Guides或此Rails Dispatch article以获取更多信息。