31 lines
854 B
PHP
31 lines
854 B
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use Illuminate\Http\Response;
|
||
|
||
class RobotsController extends Controller
|
||
{
|
||
public function index(): Response
|
||
{
|
||
// $sContent 保存 robots.txt 的具体规则
|
||
$sContent = implode("\n", [
|
||
'User-agent: *',
|
||
'Allow: /',
|
||
'',
|
||
'# 屏蔽 Laravel 系统路径',
|
||
'Disallow: /admin/',
|
||
'Disallow: /api/',
|
||
'Disallow: /storage/',
|
||
'Disallow: /vendor/',
|
||
'Disallow: /*?*', // 屏蔽带参数的重复 URL,防止稀释权重',
|
||
'',
|
||
'# 声明 Sitemap 绝对路径(请替换为你的实际域名)',
|
||
'Sitemap: ' . config('app.url') . '/sitemap.xml',
|
||
]);
|
||
|
||
return response($sContent, 200)
|
||
->header('Content-Type', 'text/plain');
|
||
}
|
||
}
|