Files
3dealer/app/Http/Middleware/PreventIndexing.php
elviraandClaude Opus 5.5 fff84f9a43 Send noindex, nofollow unless APP_INDEXABLE=true
Staging was crawlable. Opt-in flag rather than APP_ENV, since staging
runs with APP_ENV=production too. Set APP_INDEXABLE=true on the live
site only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 12:07:20 +02:00

32 lines
879 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Sends `X-Robots-Tag: noindex, nofollow` on every Laravel response unless
* config('app.indexable') is on. Opt-in rather than tied to APP_ENV, since
* staging runs with APP_ENV=production too; only the live site sets
* APP_INDEXABLE=true.
*
* robots.txt deliberately still allows crawling: a Disallow would stop
* crawlers from fetching pages at all, so they'd never see this header and
* already-indexed URLs would stay in the index.
*/
class PreventIndexing
{
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
if (! config('app.indexable')) {
$response->headers->set('X-Robots-Tag', 'noindex, nofollow');
}
return $response;
}
}