cat
cat

Reputation: 749

How can I use "redirect_to" removing requested subdomain?

If I access to http://walmart.example-site.com
it redirects me to http://walmart.example-site.com/communities/walmart

But I want it to redirect to http://example-site.com/communities/walmart

How can I fix?

My codes are.

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

Upvotes: 0

Views: 193

Answers (1)

Nich
Nich

Reputation: 1102

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

is this something you need?? Try to refer to the official routing guide under secion 3.12 Redirection.

Upvotes: 1

Related Questions