【发布时间】:2015-12-23 09:54:10
【问题描述】:
我有一个来自我的存储库 username.github.io 的 github 页面
但是,我不希望 Google 抓取我的网站,也绝对不希望它出现在搜索结果中。
只在 github 页面中使用 robots.txt 会起作用吗?我知道有停止索引 Github 存储库的教程,但是实际的 Github 页面呢?
【问题讨论】:
我有一个来自我的存储库 username.github.io 的 github 页面
但是,我不希望 Google 抓取我的网站,也绝对不希望它出现在搜索结果中。
只在 github 页面中使用 robots.txt 会起作用吗?我知道有停止索引 Github 存储库的教程,但是实际的 Github 页面呢?
【问题讨论】:
我不知道它是否仍然相关,但google says 你可以用meta 标签阻止蜘蛛:
<meta name="robots" content="noindex">
但我不确定这是否适用于所有蜘蛛或仅适用于谷歌。
【讨论】:
您可以使用robots.txt 将其添加到您的User Page 以停止对您的用户GitHub Pages 的索引。此 robots.txt 将成为您所有项目页面的活动 robots.txt,因为项目页面可作为子域(用户名)中的子目录(username.github.io/project)访问强>.github.io)。
您拥有自己的 GitHub 页面子域 (username.github.io)。根据this MOZ 和googles reference 的问题,每个子域都有/需要自己的robots.txt。
这意味着用户 username 的项目 projectname 的有效/活动 robots.txt 位于 username.github.io/robots.txt。您可以通过为您的用户创建一个 GitHub Pages 页面来将 robots.txtfile 放在那里。
这是通过创建一个名为 username.github.io 的新项目/存储库来完成的,其中 username 是您的用户名。您现在可以在此项目/存储库的主分支中创建一个 robots.txt 文件,它应该在 username.github.io/robots.txt 中可见。有关项目、用户和组织页面的更多信息可以找到here。
我已经用 Google 对此进行了测试,通过在我的项目/存储库 https://github.com/myusername/myusername.github.io/tree/master 中放置一个 html 文件来确认 myusername.github.io 的所有权,在那里创建一个 robots.txt 文件,然后使用 Google 搜索验证我的 robots.txt 是否有效控制台webmaster tools (googlebot-fetch)。 Google 确实将其列为被阻止,并且 Google Search Console webmaster tools (robots-testing-tool) 确认了这一点。
为一个项目 GitHub 页面阻止机器人:
User-agent: *
Disallow: /projectname/
为您的用户(用户页面和所有项目页面)阻止所有 GitHub 页面的机器人:
User-agent: *
Disallow: /
【讨论】:
只在 github 页面中使用 robots.txt 会起作用吗?
如果您使用的是默认的 GitHub Pages 子域,则不需要,因为 Google 只会检查 https://github.io/robots.txt。
您可以确定you don't have a master branch, or that your GitHub repo is a private one,尽管olavimmanuel 和olavimmanuel 的answer 中详细介绍了commented,但这不会改变任何事情。
但是,如果您在 GitHub Pages 站点中使用 custom domain,则可以将 robots.txt 文件放在存储库的根目录中,它会按预期工作。使用这种模式的一个例子是 Bootstrap 的 repo。
不过,bmaupin 指出,来自Google's own documentation:
robots.txt文件告诉搜索引擎爬虫,爬虫可以访问您网站上的哪些 URL。这主要用于避免您的网站因请求而过载;它不是一种将网页排除在 Google 之外的机制。
要让某个网页不被 Google 访问,请block indexing with
noindex或使用密码保护该网页。”
【讨论】:
robots.txt 放在子域中似乎将work,除非它严重过时。我注意到很多 Web 开发人员使用 Github Pages 和 Jekyll 创建他们的博客,他们的存储库中包含 robots.txt,即使他们不使用自定义域。我尚未验证这是否有效,但似乎有证据支持它按预期工作,至少对于 Google 的爬虫而言。
https://github.io/robots.txt 被重定向到https://pages.github.com/ 并且不起作用。
Google 不建议使用 robots.txt 文件不索引网站(本例中为 GitHub 页面)。事实上,即使你屏蔽了 google bot,大多数情况下它也会被编入索引。
相反,您应该在页面标题中添加以下内容,即使您没有使用自定义域,也应该易于控制。
<meta name='robots' content='noindex,nofollow' />
这将告诉 Google 不要将其编入索引。如果您只阻止 google bot 访问您的网站,它仍然会在 90% 的情况下进行索引,只是不会显示元描述。
【讨论】: