diff --git a/.env.example b/.env.example index 3c3ceb8..8be0e2b 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,8 @@ COMPOSE_PROJECT_NAME=3dealer APP_NAME=Laravel APP_ENV=local +# Leave false everywhere except the live site (sends X-Robots-Tag: noindex, nofollow) +APP_INDEXABLE=false APP_KEY= APP_DEBUG=true APP_URL=http://localhost diff --git a/app/Http/Middleware/PreventIndexing.php b/app/Http/Middleware/PreventIndexing.php new file mode 100644 index 0000000..7953edb --- /dev/null +++ b/app/Http/Middleware/PreventIndexing.php @@ -0,0 +1,31 @@ +headers->set('X-Robots-Tag', 'noindex, nofollow'); + } + + return $response; + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 0190c1b..6accf09 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -23,6 +23,9 @@ // public traffic. $middleware->trustProxies(at: '*'); + // Global, so error pages and non-`web` routes are covered too. + $middleware->append(\App\Http\Middleware\PreventIndexing::class); + // Laravel's priority list would otherwise run `auth` before core's // `locale` middleware, so the redirects below would build URLs before // URL::defaults(['locale' => …]) is set, throwing a missing-parameter error. diff --git a/config/app.php b/config/app.php index a4a9368..8f5610f 100644 --- a/config/app.php +++ b/config/app.php @@ -41,6 +41,19 @@ 'debug' => (bool) env('APP_DEBUG', false), + /* + |-------------------------------------------------------------------------- + | Search Engine Indexing + |-------------------------------------------------------------------------- + | + | Off by default, so every environment (local, staging, ...) sends + | `X-Robots-Tag: noindex, nofollow` (App\Http\Middleware\PreventIndexing). + | Set APP_INDEXABLE=true on the live site only. + | + */ + + 'indexable' => (bool) env('APP_INDEXABLE', false), + /* |-------------------------------------------------------------------------- | Application URL