【问题标题】:robots.txt allow all except few sub-directoriesrobots.txt 允许除少数子目录外的所有子目录
【发布时间】:2015-04-14 06:44:25
【问题描述】:

我希望我的网站在搜索引擎中被索引,除了少数子目录。以下是我的robots.txt 设置:

根目录下的robots.txt

User-agent: *
Allow: /

在子目录中单独robots.txt(待排除)

User-agent: *
Disallow: /

是正确的方式还是根目录规则会覆盖子目录规则?

【问题讨论】:

    标签: seo search-engine cpanel robots.txt shared-hosting


    【解决方案1】:

    User-agent: *
    Disallow: /
    

    如果您正在开发一个新网站并且不希望搜索引擎索引您不完整的网站,则上述指令很有用。 另外,您可以在here 获得高级信息

    【讨论】:

    • 这将阻止所有不是 OP 想要的内容。
    • 另请注意,并非所有爬虫都尊重 robots.txt,因此它不能替代真正的访问控制机制。
    【解决方案2】:

    您可以使用位于根目录中的 robots.txt 来管理它们。确保在 disallow 模式之前有 allow 模式。

    【讨论】:

      【解决方案3】:

      不,这是错误的。

      您不能在子目录中包含 robots.txt。您主机的 robots.txt must be placed in the document root

      如果您想禁止抓取路径以/foo 开头的网址,请在您的 robots.txt (http://example.com/robots.txt) 中使用此记录:

      User-agent: *
      Disallow: /foo
      

      这允许抓取所有内容(因此不需要Allow),除了类似的网址

      • http://example.com/foo
      • http://example.com/foo/
      • http://example.com/foo.html
      • http://example.com/foobar
      • http://example.com/foo/bar

      【讨论】:

      • 我可以有一个单独的robots.txt作为子域目录吗?
      • 每个子域都是一个新的主机,因此对于foo.example.com,robots.txt 需要在foo.example.com/robots.txt 上可用。只要机器人在访问此保留 URL 时看到 robots.txt,您如何在服务器端实现这一点并不重要。
      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多