我在 Heroku 上有暂存和生产应用程序。
对于爬虫,我设置了robots.txt文件。
之后我收到了谷歌的消息。
尊敬的网站管理员, 您网站的主机名,https://www.myapp.com/,
与您的 SSL 证书中的任何“主题名称”都不匹配,这些“主题名称”是:
*.herokuapp.com
herokuapp.com
Google 机器人读取我的暂存应用程序上的 robots.txt 并发送此消息。因为我没有设置任何阻止爬虫读取文件的东西。
所以,我正在考虑的是在暂存和生产之间更改 .gitignore 文件,但我不知道如何做到这一点。
实现这一点的最佳实践是什么?
EDIT
我用谷歌搜索了这个并找到了这篇文章http://goo.gl/2ZHal
本文说的是设置基本的 Rack 身份验证,您不需要关心 robots.txt。
我不知道基本身份验证可以阻止谷歌机器人。
看来这个解决方案比操作 .gitignore 文件更好。
Rails 3 的一个很好的解决方案是使用 Rack。这是一篇很棒的文章,概述了该过程:使用 Rack 为不同的 Robots.txt 提供服务。总而言之,您将其添加到您的routes.rb中:
# config/routes.rb
require 'robots_generator' # Rails 3 does not autoload files in lib
match "/robots.txt" => RobotsGenerator
然后在 lib/robots_generator.rb 中创建一个新文件
# lib/robots_generator.rb
class RobotsGenerator
# Use the config/robots.txt in production.
# Disallow everything for all other environments.
# http://avandamiri.com/2011/10/11/serving-different-robots-using-rack.html
def self.call(env)
body = if Rails.env.production?
File.read Rails.root.join('config', 'robots.txt')
else
"User-agent: *\nDisallow: /"
end
# Heroku can cache content for free using Varnish.
headers = { 'Cache-Control' => "public, max-age=#{1.month.seconds.to_i}" }
[200, headers, [body]]
rescue Errno::ENOENT
[404, {}, ['# A robots.txt is not configured']]
end
end
最后确保将 move robots.txt 包含到您的配置文件夹中(或者您在配置文件中指定的任何位置)RobotsGenerator
class).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)