fnllc
fnllc

Reputation: 3127

Redirect to subdomain in rails with URL params

My site has different languages. Each language has its own subdomain. I'm able to redirect the users correctly to the appropriate subdomain and URL path. However, I haven't found a way to preserve the URL parameters. I use Rails 2.3. My current redirect looks like this:

redirect_to('http://' + I18n.locale.to_s + '.' + request.domain + request.path)

How do I add the URL parameters to that or how can it be rewritten to preserve the URL parameters if there are any.

Upvotes: 1

Views: 1023

Answers (2)

fnllc
fnllc

Reputation: 3127

I solved it this way:

  split_url = request.url.partition(request.domain)
  redirect_to('http://' + I18n.locale.to_s + '.' + split_url[1] + split_url[2])

Upvotes: 1

George
George

Reputation: 118

See the Rails Guide http://guides.rubyonrails.org/i18n.html, chapter 2.5. You don't have to recreate manually the URL.

Upvotes: 0

Related Questions