fn_b/app/Http/Controllers/RobotsController.php
2026-09-12 16:32:37 +08:00

31 lines
854 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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');
}
}