For example, in order to go to a link with false parameters, http://www.domain.com/?abracadabra had 301 redirects to /

    2 answers 2

    taken from here .

    for rails 4, add this line to routes.rb :

     match '*path' => redirect('/'), via: :get 

    or

     get '*path' => redirect('/') 

    and for rails 3 this:

     match '*path' => redirect('/') 
    • Yes, it works, but only for 404 errors. Alas, there are no “left” parameters in urla. Those. domain.com/?blablabla does not redirect to root. - Alex I
    • Indeed, I answered, inattentively reading the question. and who determines the "false" parameters? - aleksandr barakin

    You need to set in ApplicationController a callback before_filter (before_action) with a method in which the incoming parameters will be analyzed and redirected if they do not meet the specified criteria.

    It is possible that in each child controller you will have to define a private method with a white list of parameters (and where filtering is not needed, provide the transfer: all instead of the list), or transfer the analysis itself to the child controller (and if there is no method in the child controller, assume that filtering is not need and all arguments valid).

    It is necessary to look at the task, as it will be more correct.