[英]Redirect All the crawlers to A specific action through routes.rb Ruby on Rails
我需要將所有web crawlers
例如, facebook
/ google
/ twitter
重定向到我的Rails API的routes.rb
中的特定操作。 我知道可以通過Ruby On Rails
constraints
來完成此操作。 但是我不知道該怎么做。 任何幫助將不勝感激!
使用ApplicationController +瀏覽器gem怎么辦? https://github.com/fnando/browser :
class ApplicationController < ActionController::Base
#...
before_action :check_if_is_crawler
def check_if_is_crawler
browser = Browser.new(request.headers['User-Agent'])
if browser.bot?
#Do whatever you want here.
end
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.