jazzman/php-robots

生成 robots.txt

2.0.1 2023-08-22 12:23 UTC

This package is auto-updated.

Last update: 2024-09-05 03:44:02 UTC


README

文本文件 "robots.txt" 的生成器

robots.txt 文件位于站点的根目录中,是一个文本文件,在其中写入了对搜索机器人的特殊指令。这些指令可能禁止站点的一些部分或页面被索引,指示域的正确“镜像”,建议搜索机器人下载服务器上的文档之间保持一定的间隔时间等。

安装

首先,使用 composer 安装此包

composer require jazzman/php-robots

或者将以下内容添加到您的 composer.json 文件的 require 部分,然后运行 composer update 来安装。

{
    "require": {
        "jazzman/php-robots": "2.0"
    }
}

使用方法

默认

use JazzMan\Robots\Robots;
use JazzMan\Robots\RobotsInterface;

Robots::getInstance()
    ->host("www.site.com")
    ->userAgent("*")
    ->allow("one","two")
    ->disallow("one","two","three")
    ->each(function (RobotsInterface $robots) {
        $robots->userAgent("Google")
            ->comment("Comment Google")
            ->spacer()
            ->allow("testing");
    })->each(function (RobotsInterface $robots) {
        $robots->userAgent("Bind")
            ->comment("Comment Bind")
            ->spacer()
            ->allow("testing");
    })->create(); // or render()

测试

$ phpunit