如何使用robots.txt只允许抓取工具访问index.php?

tod*_*odd 9 seo robots.txt web-crawler

如果我只想让抓取工具访问index.php,这会有用吗?

User-agent: *
Disallow: /
Allow: /index.php
Run Code Online (Sandbox Code Playgroud)

Sim*_*tti 20

是的,它会起作用.以下是Google网站站长工具的测试结果.

Url
http://www.example.org/index.php

Googlebot
Allowed by line 3: Allow: /index.php

Googlebot-Mobile
Allowed by line 3: Allow: /index.php
Run Code Online (Sandbox Code Playgroud)

但是,请记住,使用此配置,除非使用完整限定路径访问页面,否则不会抓取您的站点主页.换句话说,被允许http://www.example.org/是被禁止的http://www.example.org/index.php.

如果您希望可以访问您的主页,这里是您文件的更好版本.

User-agent: *
Disallow: /
Allow: /index.php
Allow: /$
Run Code Online (Sandbox Code Playgroud)


Jan*_*nco 2

您可以使用Google Robots 工具进行结账。我永远不会在 robots 文件中放入任何秘密目录,因为我猜测像下面这样的行对于某些蜘蛛来说就像蜂蜜一样。

Disallow: /secret
Run Code Online (Sandbox Code Playgroud)