Cezar Halmagean
Cezar Halmagean

Reputation: 902

how to have locale/tld based urls/routes?

Is there a way to have different URLs for each locale/tld (especially for SEO reasons) ?

So say if I come thru mysite.us I could have:

http://mysite.com/some-nice-url

and if come thru mysite.org, I could have:

http://mysite.fr/another-very-nice-url

Thank you

Upvotes: 1

Views: 490

Answers (1)

moritz
moritz

Reputation: 25767

What you could do is:

class ApplicationController < ActionController::Base
  ..
  before_filter :domain_locale
  protected
    def domain_locale
      I18n.locale = request.host.split('.').last
    end

  ...
end

of course, you could add some more sophistication within domain_locale.

So for your routes.rb, you can add constraints like this:

match 'soem_nice-url', :to => 'nice#some', :constraints => {:host => 'mysite.com'}
match 'soem_nice-url', :to => 'nice#another', :constraints => {:host => 'mysite.fr'}

Upvotes: 2

Related Questions