我只向我的 CDN 提供图像。
我在我的 CDN 域中设置了一个 robots.txt 文件,该文件与在我的“正常”www 域中设置的文件是分开的。
我想格式化我的 CDN 域中的 CDN robots.txt 文件,以便阻止对除图像之外的所有内容(无论其位置如何)进行索引?
所有这一切的原因是我想避免重复的内容。
这是正确的吗?
User-agent: *
Disallow: /
Allow: /*.jpg$
Allow: /*.jpeg$
Allow: /*.gif$
Allow: /*.png$
最佳答案
如果您在某些文件夹中有所有图像,您可以使用:
仅适用于 google-bot:
User-agent: Googlebot-Image
Allow: /some-images-folder/
对于所有用户代理:
User-agent: *
Allow: /some-images-folder/
Additionally, Google has introduced increased flexibility to the robots.txt file standard through the use asterisks. Disallow patterns may include "*" to match any sequence of characters, and patterns may end in "$" to indicate the end of a name.
要允许特定文件类型(例如.gif 图像),您可以使用以下 robots.txt 条目:
User-agent: Googlebot-Image
Allow: /*.gif$
Info 1: By default (in case you don't have a robots.txt), all content is crawled.
Info 2: The Allow statement should come before the Disallow statement, no matter how specific your statements are..
这是 robot's exclusion standard 的 wiki 链接以获得更详细的描述。
据此,您的示例应如下所示:
User-agent: *
Allow: /*.jpg$
Allow: /*.jpeg$
Allow: /*.gif$
Allow: /*.png$
Disallow: /
注意:正如 nev 在他的评论中指出的,注意扩展末尾的查询字符串也很重要,例如 image.jpg?x12345
,所以也包括
Allow: /*.jpg?*$
关于cdn - 使用 robots.txt 文件来阻止除图像之外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52849351/