cdn - 使用 robots.txt 文件来阻止除图像之外的所有内容

标签 cdn robots.txt

我只向我的 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/

相关文章:

.htaccess - Mod_rewrite 结合 SEO 友好的 url 和 CDN

meta - 多个机器人元标记

html - 阻止站点 Flash 播放器配置信息显示在 Google 上

wordpress - 更改 Wordpress 站点中的 robots.txt 文件导致 SEO 困惑

javascript - 我什么时候应该合并我的 JS 和 CSS 文件?

Jquery Migrate CDN 回退条件

amazon-web-services - Amazon CloudFront 的开源成熟等效项是什么?

drupal - 我可以告诉站点爬虫访问某个页面吗?

robots.txt - 如何允许 robots.txt 中的网址但不允许类似于 allowed 的其他网址

jquery - Google 的 CDN 上是否有 jQuery UI CSS 主题的缩小/压缩版本?