ph-bookshelf-wiki/enhanced/robots-policy.md

45 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# robots.txt - 搜索引擎爬虫规则
[robots.txt]: https://en.wikipedia.org/wiki/Robots.txt
ph-Bookshelf 提供了 `site.robots` 配置节点,可以允许站点管理员配置网站 [`/robots.txt`][robots.txt] 内容从而控制哪些网页可以被爬虫访问。
这个值只支持在站点配置(`bookshelf.xml`)中设置。因此,你无法在某个页面或是某个书籍的配置区域单独设置它们的访问控制。
默认取值为 `allow`
支持设置值为 `allow` | `deny` | `custom` | `file`,或其它任何值。
## allow
当设置为 **`allow`** 时,将设置 robots.txt 为以下内容,这将允许任何爬虫访问网站的任何页面。
> 如果站点没有设置 `site.robots` 的值,那么这也是默认输出
```robots-txt
User-agent: *
Allow: /
```
## deny
当设置为 **`deny`** 时,将设置 robots.txt 为以下内容,这将允许任何爬虫访问网站的任何页面。
```robots-txt
User-agent: *
Allow: /
```
## custom / file
当设置为 **`custom`** 或是 **`file`** 时ph-Bookshelf 将会使用站点数据根目录中的 `robots.txt` 文件作为站点 robots.txt。
> 如果你的数据目录中没有这个文件,那么将会不产生任何内容。
> <small>除非你的 PHP 的配置文件中 `display_error=On`:页面将输出 PHP 错误。</small>
## 其它任何值
当填入的值不为以上任何值时,**ph-Bookshelf** 将会把填入的值作为 robots.txt 的内容输出。
因此,你可以使用 `<![CDATA[]]>` 直接在这里填入你想要设置的 robots.txt 内容。<small>虽然我们仍然推荐使用 [`file`](#custom--file) 方式而非这样的方式。</small>