robots.txt中的常见规则

时间:2012-12-13 15:57:10

标签: robots.txt

如何使用1.html, 2.html, ..., [0-9]+.html禁止robots.txt(就regexp而言)的网址?

1 个答案:

答案 0 :(得分: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