如果我访问 http://walmart.example-site.com
它将我重定向到 http://walmart.example-site.com/communities/walmart
但我希望它重定向到 http://example-site.com/communities/walmart
我该如何解决?
我的代码是。
的routes.rb
constraints(:subdomain => /.+/) do
root :to => 'communities#subdomain_redirect'
end
communities_controller.rb
def subdomain_redirect
@community = Community.find_by_community_name(request.subdomain)
redirect_to @community
end
答案 0 :(得分:1)
match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}" }
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }
这是你需要的吗?尝试参考secion 3.12 Redirection下的官方路由指南。