为使用多个存储库的 github 页面编写机器人.txt的最佳方法是什么?



我正在使用Github页面与Jekyll一起构建我的个人网站。我在username.github.io存储库中有一个总部站点,在projectA存储库中有一个项目 A 站点,在projectB存储库中有一个项目 B 等等。我在username.github.io存储库下放置了一个CNAME文件,以便我的所有站点都在自定义域名(www.mydomain.com)下。我注意到robots.txt文件指向每个存储库下的sitemap.txt文件,sitemap.txt只能包含每个单独存储库中页面的页面链接。所以,我有几个问题:

  1. 由于我的网站结构为与单个存储库中的页面相对应的www.mydomain.comwww.mydomain.com/projectAwww.mydomain.com/projectB等,即使username.github.iohead 存储库下的sitemap.txt只有单个存储库中生成的页面链接,搜索引擎也会识别我的所有网站页面吗?

  2. 在我的情况下,编写robots.txt文件的最佳方法是什么?

谢谢! 齐

标准和免责声明

机器人中的Sitemap:.txt根据维基百科是一个非标准扩展。请记住:

使用 Sitemap 协议并不能保证网页包含在搜索引擎中,但会为网络抓取工具提供提示,以便更好地抓取您的网站。

维基百科还将allow:列为非标准扩展名。

机器人中的多个站点地图.txt

您可以为每个机器人.txt文件指定多个站点地图文件。在机器人中指定多个站点地图时.txt格式如下:

Sitemap: http://www.example.com/sitemap-host1.xml
Sitemap: http://www.example.com/sitemap-host2.xml

站点地图索引

还有一种类型的站点地图文件是站点地图文件的索引。

如果您有站点地图索引文件,则可以仅包含该文件的位置。您无需列出索引文件中列出的每个站点地图。

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/sitemap1.xml.gz</loc>
<lastmod>2004-10-01T18:23:17+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.example.com/sitemap2.xml.gz</loc>
<lastmod>2005-01-01</lastmod>
</sitemap>
</sitemapindex>

<lastmod>是可选的。

关于排除内容

借助站点地图协议,您可以让搜索引擎知道您希望将哪些内容编入索引。要告诉搜索引擎您不想编入索引的内容,请使用漫游器.txt文件或漫游器元标记。有关如何从搜索引擎中排除内容的详细信息,请参阅 robotstxt.org。

如果您希望搜索引擎不索引任何内容,则应将其放在robots.txt文件(在用户页面存储库中)中:

User-agent: *
Disallow: /project_to_disallow/
Disallow: /projectname/page_to_disallow.html

或者,您可以使用机器人标签。

建议

User-agent: *
Disallow: /project_to_disallow/
Disallow: /projectname/page_to_disallow.html
Sitemap: http://www.example.com/sitemap.xml
Sitemap: http://www.example.com/projectA/sitemap.xml
Sitemap: http://www.example.com/projectB/sitemap.xml

或者,如果您使用的是站点地图索引文件

User-agent: *
Disallow: /project_to_disallow/
Disallow: /projectname/page_to_disallow.html
Sitemap: http://www.example.com/siteindex.xml

http://www.example.com/siteindex.xml看起来像什么样

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>http://www.example.com/projectA/sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>http://www.example.com/projectB/sitemap.xml</loc>
</sitemap>
</sitemapindex>

有关如何使用 GitHub 页面设置机器人.txt的信息,请参阅此处的答案。

在哪里 简短的回答:在你 网页服务器。来源 : http://www.robotstxt.org/robotstxt.html

您还可以在 google 文档中看到,www.mydomain.com/folder/robots.txt 网址不会被抓取。

基本 www.mydomain.com/robots.txt 可以是:

User-agent: *

这将指示爬网程序通过以下链接遍历所有 www.mydomain.com 文件层次结构。

如果没有 www.mydomain.com 页面引用您的项目页面,则可以添加:

User-agent: *
allow: /ProjectA
allow: /projectB