robots-txt
所属分类:工具库
开发工具:PHP
文件大小:0KB
下载次数:0
上传日期:2022-02-18 08:19:11
上 传 者:
sh-1993
说明: 用于以编程方式生成robots.txt的包。
(A package for generating a robots.txt programmatically.)
文件列表:
robots-txt-1.x/ (0, 2022-02-18)
robots-txt-1.x/CHANGELOG.md (247, 2022-02-18)
robots-txt-1.x/LICENSE (1515, 2022-02-18)
robots-txt-1.x/UPGRADE.md (22, 2022-02-18)
robots-txt-1.x/composer.json (720, 2022-02-18)
robots-txt-1.x/phpunit.xml (1367, 2022-02-18)
robots-txt-1.x/src/ (0, 2022-02-18)
robots-txt-1.x/src/Builder/ (0, 2022-02-18)
robots-txt-1.x/src/Builder/RobotsTxtBuilder.php (2513, 2022-02-18)
robots-txt-1.x/src/Builder/UserAgentSection.php (3025, 2022-02-18)
robots-txt-1.x/src/Exception/ (0, 2022-02-18)
robots-txt-1.x/src/Exception/InvalidPathException.php (130, 2022-02-18)
robots-txt-1.x/src/Exception/InvalidSitemapUrlException.php (136, 2022-02-18)
robots-txt-1.x/src/Exception/RobotsTxtException.php (315, 2022-02-18)
robots-txt-1.x/tests/ (0, 2022-02-18)
robots-txt-1.x/tests/Builder/ (0, 2022-02-18)
robots-txt-1.x/tests/Builder/RobotsTxtBuilderTest.php (3570, 2022-02-18)
robots-txt-1.x/tests/Builder/UserAgentSectionTest.php (2965, 2022-02-18)
robots-txt-1.x/tests/bootstrap.php (328, 2022-02-18)
robots-txt-1.x/vendor-bin/ (0, 2022-02-18)
robots-txt-1.x/vendor-bin/test/ (0, 2022-02-18)
robots-txt-1.x/vendor-bin/test/composer.json (60, 2022-02-18)
Robots.txt Library
==================
Usage
-----
First, you need to create a builder. With this builder you can create sections for different user agents and add the directives to it.
You can also add a header to the robots.txt and register your sitemap URLs.
### Adding Sections
```php
use Becklyn\RobotsTxt\Builder\RobotsTxtBuilder;
$builder = new RobotsTxtBuilder();
// adding a section
$builder->getSection("google")
->allow("/public")
->disallow("/admin")
->crawlDelay(20);
$builder->getSection("bing")
->allow("/public")
->disallow("/admin")
->disallow("/private")
->crawlDelay(15);
```
If multiple search engines have the same directives, you can add one section for all of them:
```php
$builder->getSection("google", "bing")
->allow("/public")
->disallow("/admin")
->crawlDelay(20);
```
The builder tries to bundle combine the directives of multiple sections if possible:
```php
$builder->getSection("google")
->allow("/public");
// ... some code ...
$builder->getSection("google")
->disallow("/admin")
// will produce a single entry:
//
// User-Agent: google
// Allow: /public
// Disallow: /admin
```
### Sitemaps
```php
$builder
->addSitemap("https://example.org/sitemap.xml.tar.gz")
->addSitemap("https://example.org/sitemap.xml");
```
### Header
You can also add a header which will be included at the very top:
```php
$builder
->setHeader("This is some example text");
$builder->getSection("google")
->allow("/public");
// Will produce:
//
// # This is some example text
//
// User-Agent: google
// Allow: /public
```
### Outputting the robots.txt
```php
$content = $builder->getFormatted();
file_put_contents("robots.txt", $content);
```
近期下载者:
相关文件:
收藏者: