简体   繁体   中英

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.

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])

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM