I want to redirect all root requests to a /pages/home
url, but I want to keep all the params used in the original request.
So:
http://myserver.com/?param1=value1¶m2=value2
Becomes
http://myserver.com/pages/home?param1=value1¶m2=value2
There are several SO questions about passing params in a redirect
but I haven't found any related to passing request's params.
# routes.rb root :to => redirect { |params, request| "/pages/home?#{request.params.to_query}" }
You can also play with the request.params
to build the new path
:
root :to => redirect { |params, request| "/pages/#{request.params[:page]}.html?#{request.params.to_query}" }
The other answer works but leaves a ?
at the end in case there are no parameters.
This seems to do the trick without the side effects:
root to: redirect(path: '/quick_searches/new')
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With