根据标志重定向到新URL

时间:2017-05-02 10:25:46

标签: ruby-on-rails ruby

我想将所有请求重定向到我的Ruby on Rails网站,将其重定向到基于标志的相同参数的新URL。基于该标志,用户应该是

1.被引导到错误  2.转到新网址  3.request由同一台服务器处理。

将重定向逻辑放在application_controller的before_filter中会在重定向到errorpage时导致循环依赖。

class ApplicationController
  before_filter :redirect_if_old

  def redirect_if_old
    flag = get_from_rules_engine # The value is obtained from a rules engine
    if(flag == 1)
        redirect_to errorpage_path
    else
        if (flag == 2)
            redirect_to "https:new-url#{request.fullpath}", :status => :moved_permanently
        end
    end
  end
end

1 个答案:

答案 0 :(得分:0)

尝试return,如下所示:

class ApplicationController
  before_filter :redirect_if_old

  def redirect_if_old
    if(flag == 1)
        redirect_to errorpage_path and return
    else
        if (flag == 2)
            redirect_to "https:new-url#{request.fullpath}" and return, :status => :moved_permanently 
        end
    end
  end