Skip to content

Instantly share code, notes, and snippets.

@0x7466
Last active August 8, 2016 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x7466/52febcf079f7182bfeb3 to your computer and use it in GitHub Desktop.
Save 0x7466/52febcf079f7182bfeb3 to your computer and use it in GitHub Desktop.
SEO friendly root URL in Rails
Rails.application.routes.draw do
# This isn't the best solution
# if you want to get to the
# root page and you do I18n,
# because it adds a parameter
# if you link to the root page.
#
# FormHelper Example: <%= link_to "Home", root_path %>
# Result: http://example.com/?locale=en
#
# This isn't very SEO friendly.
root 'welcome#index'
# Better solution
#
# Example: <%= link_to "Home", i18n_root_path %>
# Result: http://example.com/en
#
# Much SEO friendlier :)
get ':locale' => 'welcome#index', as: :i18n_root
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment