1

我正在尝试完成类似于纽约时报和其他新闻网站的事情,当访问者从谷歌引荐时显示完整文章,但仅在直接访问时显示预览。

我相信要检查访问者是否来自谷歌,我需要检查:request.env["HTTP_REFERER"]

这个对吗?它只是名称“google”的匹配项吗?控制器中的逻辑是这样的吗:

if request.env["HTTP_REFERER"].match "google"
  # do action/set variable etc.
4

1 回答 1

2

Yeah you are pretty much right about all that. Just check via a regex if the user comes from google - and display the other site. Example code:

if request.env["HTTP_REFERER"] =~ /google\.[a-z]{2,4}/
  # do the special google stuff here
  render layout: "special_google_layout"
else
  # do the regular stuff here
end

This regex checks the referer for the string "google" followed by a dot and 2 - 4 small letters.

于 2012-04-07T01:27:38.050 回答