【问题标题】:Wildcards in robots.txtrobots.txt 中的通配符
【发布时间】:2014-03-02 22:37:47
【问题描述】:

如果在 WordPress 网站中我的类别按此顺序排列:

-Parent
--Child
---Subchild

我将永久链接设置为: %category%/%postname%

举个例子。 我创建帖子名称为“体育游戏”的帖子。 它的标签是运动游戏。 它的完整网址是:domain.com/parent/child/subchild/sport-game 为什么我使用这种永久链接正是为了更容易阻止 robots.txt 中的某些内容。

现在这是我有疑问的部分。 在 robots.txt 中:

User-agent: Googlebot
Disallow: /parent/*
Disallow: /parent/*/*
Disallow: /parent/*/*/*

Disallow: /parent/* 这条规则的含义是它阻止domain.com/parent/child 但不是domain.com/parent/child/subchild 而不是domain.com/parent/

Disallow: /parent/*/*/* 阻止domain.com/parent/child/subchild/ 的意思是,它只阻止子子项,而不是子项,不是父项,也不是子项下的帖子?

【问题讨论】:

    标签: web-crawler robots.txt


    【解决方案1】:

    请注意,Disallow 中的 * 通配符不是原始 robots.txt 规范的一部分。一些解析器支持它,但由于没有规范,它们可能都会以不同的方式处理它。

    您似乎对 Googlebot 感兴趣,请查看Google’s robots.txt documentation

    在示例中,* 的意思很明显

    任何字符串

    “任何字符串”当然也可以包含/

    因此,您的第一行 Disallow: /parent/* 应该阻止路径以 /parent/ 开头的每个 URL,包括由斜杠分隔的路径段。

    请注意,这与原始 robots.txt 规范中的 Disallow: /parent/ 相同,它还会阻止路径以 /parent/ 开头的任何 URL,例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多