djstarcom / laravel-robots-manager
Laravel robots.txt 管理器
v2.0.1
2021-06-15 07:05 UTC
Requires
- php: >=7.2
- laravel/framework: ~6.20.26|~7.0|~8.0
Requires (Dev)
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0
- roave/security-advisories: dev-master
- scrutinizer/ocular: dev-master
- squizlabs/php_codesniffer: ^2.4 || ^3.0
This package is auto-updated.
Last update: 2024-09-16 13:36:27 UTC
README
安装
首先,通过composer安装包
composer require "djstarcom/laravel-robots-manager"
包会自动注册自己。
使用方法
删除项目默认的public/robots.txt
将以下内容添加到您的路由文件中
Route::get('robots.txt', function () { if (App::environment() == 'production') { // If on the live server, serve a nice, welcoming robots.txt. RobotsManager::addUserAgent('*'); RobotsManager::addSitemap('sitemap.xml'); } else { // If you're on any other server, tell everyone to go away. RobotsManager::addDisallow('*'); } return Response::make(RobotsManager::generate(), 200, ['Content-Type' => 'text/plain']); });
有关API使用的参考,请参阅RobotsManager.php