3

我想检测到我的 Rails 站点的引荐来源域,如果引荐来源与域匹配,我希望它们被重定向到特定页面。

我怎么能这样做?

4

2 回答 2

2
class MyController < ApplicationController
  def my_action
    if request.referer =~ /a_domain_pattern/
      redirect_to a_specific_page_path
    end
  end
end
于 2013-07-10T20:26:06.990 回答
1

您可以在 ApplicationController 中添加限制:

class ApplicationController < ActionController::Base
  before_action :check_referer

  private

  def check_referer
    if request.referer =~/.hotdeals\.com./
      flash[:info] = "You are being redirected to a proper place"
      redirect_to url
    end
  end
end
于 2013-07-10T21:35:34.033 回答