所以我有一个名为的URL
http://localhost:3000/insurance?utm_source=article&utm_content=driving
现在需要将此URL重定向到此
http://localhost:3000/insurance-for-all?utm_source=article&utm_content=driving
我尝试在routes.rb这样做
get '/insurance', to: redirect { |params|"/insurance-for-all?#{params.to_query}" }
但它不起作用。
有没有办法重定向到新的URL与params仍然完好无损?
谢谢
如果你只使用path
选项重定向,那么所有参数也将被发送:
get '/insurance', to: redirect(path: "/insurance-for-all")
你需要有request
对象来设置parameters
完好无损。
按照documentation尝试
get '/insurance', to: redirect { |params, request| "/insurance-for-all?#{request.params.to_query}" }