sagsoz06 / laravel-5-robots
Laravel 5 的 Robots.txt 生成器
0.1.1
2020-05-31 00:41 UTC
Requires
- php: >=5.4.0
- illuminate/support: >=5.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ~4.6
This package is not auto-updated.
Last update: 2024-09-16 19:59:11 UTC
README
这是一个 https://github.com/jayhealey/Robots 的分支。原始仓库的开发似乎已经停止。
此分支的目的是引入 Laravel 5 兼容性以及 PSR-4 和 PSR-2(适用于 Laravel 5.1)。
安装
第1步:Composer
将包添加到您的 composer.json
文件中
{
"require": {
"ellisthedev/laravel-5-robots": "~0.1.0"
}
}
第2步:配置
将以下内容添加到您的 config/app.php
文件中的 providers
数组
'EllisTheDev\Robots\RobotsServiceProvider',
您也可以选择性地将以下内容添加到 aliases
数组
'Robots' => 'EllisTheDev\Robots\RobotsFacade',
使用
将以下内容添加到您的路由文件
Route::get('robots.txt', function () { if (App::environment() == 'production') { // If on the live server, serve a nice, welcoming robots.txt. Robots::addUserAgent('*'); Robots::addSitemap('sitemap.xml'); } else { // If you're on any other server, tell everyone to go away. Robots::addDisallow('*'); } return Response::make(Robots::generate(), 200, ['Content-Type' => 'text/plain']); });
请参考 Robots.php 了解 API 使用方法。