【问题标题】:Common rule in robots.txtrobots.txt 中的通用规则
【发布时间】:2012-12-13 15:57:09
【问题描述】:

如何使用robots.txt 禁止1.html, 2.html, ..., [0-9]+.html(就正则表达式而言)之类的网址?

【问题讨论】:

标签: robots.txt


【解决方案1】:

原始 robots.txt 规范不支持正则表达式/通配符。但是,您可以屏蔽以下网址:

  • example.com/1.html
  • example.com/2367123.html
  • example.com/3
  • example.com/4/foo
  • example.com/5/1
  • example.com/6/
  • example.com/7.txt
  • example.com/883
  • example.com/9to5

与:

User-agent: *
Disallow: /0
Disallow: /1
Disallow: /2
Disallow: /3
Disallow: /4
Disallow: /5
Disallow: /6
Disallow: /7
Disallow: /8
Disallow: /9

如果您只想阻止以单个数字开头后跟.html 的网址,只需附加.html,例如:

User-agent: *
Disallow: /0.html
Disallow: /1.html
…

但是,此不会阻止,例如,example.com/12.html

【讨论】:

  • 但我有无限数量的此类页面:)
  • @Dmytro:好吧,如果 a) 他们all09 开头,并且 b)希望允许任何以0...9 开头的网址。
  • 如果您的所有 URL 都以数字结尾,后跟 .html,我添加了另一个变体。如果我的示例不适合您,您应该准确描述您想要阻止的 URL 以及您想要允许的 URL。
猜你喜欢
  • 1970-01-01
  • 2011-06-17
  • 2016-06-23
  • 2023-02-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 2014-03-29
相关资源
最近更新 更多