1

我正在使用 Heroku 管道。所以当我推送我的应用程序时,它会被推送到登台应用程序

https://appname.herokuapp.com/

如果一切正确,我将该应用程序推广到生产。没有新的构建过程。它与第一次为登台构建的应用程序相同。

https://appname.com/

问题是这会导致重复内容的问题。站点是彼此的克隆。完全相同的。我想从 Google 索引和搜索引擎中排除暂存应用程序。

我想到的一种方法是使用robots.txt文件。

为此,我应该这样写

User-agent: *
Disallow: https://appname.herokuapp.com/

使用绝对路径,因为这个文件将在登台和生产应用程序的服务器上,我只想从谷歌索引中删除登台应用程序,而不是接触生产应用程序。

这是正确的方法吗?

4

2 回答 2

3

不,该Disallow字段不能采用完整的 URL 引用。您的 robots.txt 会屏蔽以下网址:

  • https://example.com/https://appname.herokuapp.com/
  • https://example.com/https://appname.herokuapp.com/foo

Disallow值始终表示URL 路径的开头

要阻止 下的所有 URL https://appname.herokuapp.com/,您需要:

Disallow: /

所以你必须为https://appname.herokuapp.com/和使用不同的 robots.txt 文件https://appname.com/

如果你不介意机器人爬行https://appname.herokuapp.com/,你可以noindex改用。但这也需要两个站点的不同行为。不需要不同行为的替代方法可能是使用canonical. 这会向爬虫传达哪个 URL 是首选的索引。

<!-- on https://appname.herokuapp.com/foobar -->
<link rel="canonical" href="https://appname.com/foobar" />
<!-- on https://appname.com/foobar -->
<link rel="canonical" href="https://appname.com/foobar" />
于 2018-08-01T14:41:08.047 回答
-1

不,使用您的建议会阻止所有搜索引擎/机器人访问https://appname.herokuapp.com/.

相反,您应该使用的是:

User-agent: Googlebot
Disallow: /

这只会阻止Googlebot访问https://appname.herokuapp.com/. 记住,机器人可以忽略该robots.txt文件,这比什么都好。但 Google 会按照您的要求进行操作。

编辑

在看到 unor 的建议后,不可能通过 URL 禁止,所以我已经从我的答案中改变了这一点。但是,您可以通过特定文件来阻止,例如/appname/,或者您可以/用来阻止 Googlebot 访问任何内容。

于 2018-08-01T10:50:18.487 回答