redirect with saving url params?

135 views Asked by At

some time ago forum was created in public directory of a rails app. then forum was moved to a sub-domain.
I've created a redirect for 'domain.com/forum' => 'forum.domain.com by editing routes & creating redirect action.
My question is: how may i preserve url params (ex. 'domain.com/forum?thread1&=1' => 'forum.domain.com?thread1=1' & etc.)
My code as follows:

routes.rb:
map.forum '/forum', :controller => "application", :action => "redirect_to_forum"

application_controller.rb
def redirect_to_forum
redirect_to "http://forum.domain.com"
end

1

There are 1 answers

0
Gopal S Rathore On BEST ANSWER

You can try with getting request url in a hash :-> and then try to preserve your parameters,

on the top of the page use

require 'cgi'

and then get the url wherever you want to get it and use it. After getting parameters in hash u can use them to reconstruct your new url.

 parameters  = CGI::parse(request.url)

parameter will contain the hash of your all parameters.