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>
This commit is contained in:
elviraandClaude Opus 5.5 committed 2026-10-27 12:07:20 +02:00
1 parent b2f53ea952
commit fff84f9a43
4 files changed
+49

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
<?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;
}
}