How to remove parameters from the root URL if it does I18n
Outdated (at least for Google)
Recently I studied SEO a bit and found out that search engines somehow "don't like" parameters in the URL. Comprehensible since they aren't really human readable or tend to not be permanent.
The problem now is, what if I followed the Rails Guides to set up I18n and then want to link to the
root_path. It links to the root but adds a
?locale=en to the URL. So
Even if SEO isn't affected about this anymore, I think it looks much nicer if the URL looks like
http://www.example.com/en instead of
I found a pretty straightforward solution.
I just added another route to my
Rails.application.routes.draw do root 'welcome#index' # ... get ':locale' => 'welcome#index', as: :i18n_root end
Now I just have to add the
i18n_root_path to the links which link to the root path and everything works fine.
The returned URL:
Another possible solution, if I would have a lot of links already in the app, is to create a custom root.
Rails.application.routes.draw do # root 'welcome#index' <= We don't want to have a default root # ... get ':locale' => 'welcome#index', as: :root end
Hope this helps other people as well.
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?