robots.txt - robots.txt 中只允许目录中的一个文件吗?

标签 robots.txt

我只想允许目录 /minsc 中的一个文件,但我想禁止该目录的其余部分。

现在 robots.txt 中是这样的:

User-agent: *
Crawl-delay: 10
# Directories
Disallow: /minsc/

我想要允许的文件是/minsc/menu-leaf.png

我害怕造成损害,所以我不知道是否必须使用:

A)

User-agent: *
Crawl-delay: 10
# Directories
Disallow: /minsc/
Allow: /minsc/menu-leaf.png

B)

User-agent: *
Crawl-delay: 10
# Directories
Disallow: /minsc/*    //added "*" -------------------------------
Allow: /minsc/menu-leaf.png

感谢并抱歉我的英语。

最佳答案

根据the robots.txt website :

To exclude all files except one

This is currently a bit awkward, as there is no "Allow" field. The easy way is to put all files to be disallowed into a separate directory, say "stuff", and leave the one file in the level above this directory:

User-agent: *

Disallow: /~joe/stuff/

或者,您可以明确禁止所有不允许的页面:

User-agent: *

Disallow: /~joe/junk.html

Disallow: /~joe/foo.html

Disallow: /~joe/bar.html

根据Wikipedia ,如果您要使用“Allow”指令,则应将其放在“Disallow”之前以获得最大兼容性:

Allow: /directory1/myfile.html
Disallow: /directory1/

此外,您应该将爬行延迟放在最后,根据 Yandex :

To maintain compatibility with robots that may deviate from the standard when processing robots.txt, the Crawl-delay directive needs to be added to the group that starts with the User-Agent record right after the Disallow and Allow directives).

所以,最后,您的 robots.txt 文件应如下所示:

User-agent: *
Allow: /minsc/menu-leaf.png
Disallow: /minsc/
Crawl-delay: 10

关于robots.txt - robots.txt 中只允许目录中的一个文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34914054/

相关文章:

seo - 链接果汁优先 www。和域名

robots.txt - Robots.txt允许子文件夹但不允许父文件夹

robots.txt - 如何禁止所有动态网址 robots.txt

seo - 限制机器人访问(特定)查询字符串(参数)值?

.htaccess - 仅允许通过 http 访问 robots.txt,其他通过 https 访问

bots - 使图像只能由 Googlebot-Image 访问,并通过 robots.txt 阻止其他机器人

wordpress - 不理解这个 robots.txt

node.js - robots.txt 未通过 node.js 路由显示发送纯文本

robots.txt - 在 robots.txt 文件中使用 "Disallow:/*?"

python - 使用 mechanize 检索 robots.txt 时出现 HTTP 403 错误