我想检测到我的 Rails 站点的引荐来源域,如果引荐来源与域匹配,我希望它们被重定向到特定页面。
我怎么能这样做?
class MyController < ApplicationController
def my_action
if request.referer =~ /a_domain_pattern/
redirect_to a_specific_page_path
end
end
end
您可以在 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