2013-01-03 24 views
0

如果我訪問http://walmart.example-site.com
它重定向我http://walmart.example-site.com/communities/walmart如何使用「redirect_to」刪除請求的子域名?

但我想它重定向到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 

回答

1
match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}" } 
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" } 

是這是你需要的?嘗試參考secion 3.12重定向下的官方路由指南。

+0

這不是。對不起我的可憐的知識。 – cat

+0

是你的目的是爲根設置爲子域到你的根? – Nich

+0

所有我想要的是當它重定向時刪除子域。這就是 – cat