ganey / robots
Laravel 5 的 Robots.txt 生成器
Requires
- php: >=5.4.0
- illuminate/support: >=5.0
README
这是一个基于 https://github.com/jayhealey/Robots/ 的分支,用于更新 Laravel 5。
原始的 Robots 类由 TutsGlobal.com 的 dragonfire1119 编写:http://tutsglobal.com/topic/15-how-to-make-a-robotstxt-in-laravel-4/
该类本身(Robots.php
)可以在任何 PHP 5.4+ 网站上运行。可以通过删除命名空间轻松修改为 5.2。
此存储库通过 Composer 提供了简单的集成,包括 Laravel 5 的服务提供程序和外观,以及一组 PHPUnit 测试。
查看 Robots.php
类以全面了解其功能。
安装
步骤 1. 下载
与 Composer 包一样,有两种安装方式
您可以通过 Composer 安装。选择“master”作为包的版本。
composer require Ganey/robots
或将以下内容添加到您的 composer.json
中的 require
部分,然后运行 composer update
来安装。
{ "require": { "Ganey/robots": "~2.0" } }
步骤 2. 使用
Laravel
通过 Composer 安装后,您需要添加服务提供程序。通过将以下内容添加到应用程序配置的 'providers' 部分(通常是 app/config/app.php
)来完成此操作
Ganey\Robots\RobotsServiceProvider::class,
将外观添加到应用程序配置的 'aliases' 部分(通常是 app/config/app.php
)
'Robots' => \Ganey\Robots\RobotsFacade::class
请注意,外观允许您通过简单地调用 Robots::doSomething()
来使用类。
使用 Robots 的最快方式是在您的 /app/routes.php
文件中为 robots.txt
设置回调式路由。
<?php Route::get('robots.txt', function() { // If on the live server, serve a nice, welcoming robots.txt. if (App::environment() == 'production') { 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, array('Content-Type' => 'text/plain')); });
就这样!您可以根据需要显示不同复杂度的 robots.txt
文件。
许可
MIT