我想将引荐来源网站检测到我的Rails网站,如果引荐来源与域名匹配,我希望将它们重定向到特定页面。
我怎么能这样做?
答案 0 :(得分:2)
class MyController < ApplicationController
def my_action
if request.referer =~ /a_domain_pattern/
redirect_to a_specific_page_path
end
end
end
答案 1 :(得分:1)
您可以在ApplicationController中添加restrition:
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