redirect to root_path
My route开发者_StackOverflow社区 has root set to :
root :to => "posts#index", :locale => :en
But /en/posts/ and /en/posts/index is still accessible, showing "duplicate" content from the root_path. I would like to redirect to root_path, if one of those paths is used.
That way, I can avoid duplicate content in search engines and my users have a more consistent experience: a resource lives on only one place and one place only (REST).
You can turn off the posts/index url by editing the posts resource in your routes.rb file to look like this:
resources :posts, :except => :index
If this gives you issues with redirection, read the rails guides on routing, specifically section 3.12 Redirection
I recently found a solution to this issue by using the following in my routes.rb:
get "/en/posts" => redirect("/")
resources :posts
root :to => "posts#index", :locale => :en
Requests to /en/posts gets 301 redirected (Moved permanently) to the root path
精彩评论