I have a multi-language rails website created using the Rails I18n API with URLs like
"example.com/en/about" or "example.com/de/about" or "example.com/en/contact"
etc.
This works fine as is, but I would like that if a user goes to "example.com/about" (without the language part in the URL), he'd be redirected to the respective page in a default language, e.g. to "example.com/en/about"
My config/routes.rb looks like:
Example::Application.routes.draw do
get '/:locale' => 'static_pages#home'
scope "/:locale" do
root "static_pages#home"
match 'about', to: 'static_pages#about', via: 'get'
match 'contact', to: 'contact#new', via: 'get'
end
resources "contact", only: [:new, :create]
end
I could redirect the URL on the server (apache) level, but I'd prefer to do this in rails.