From 349e7d19aa8e2d2fc47dc69ee194d394c0df0752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20Salihovi=C4=87?= Date: Sun, 23 Jun 2024 15:07:29 +0200 Subject: [PATCH] Separate api and admin robots.txt --- public/{robots.txt => robots-admin.txt} | 0 public/robots-api.txt | 2 ++ routes/api.php | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) rename public/{robots.txt => robots-admin.txt} (100%) create mode 100644 public/robots-api.txt diff --git a/public/robots.txt b/public/robots-admin.txt similarity index 100% rename from public/robots.txt rename to public/robots-admin.txt diff --git a/public/robots-api.txt b/public/robots-api.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/public/robots-api.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/routes/api.php b/routes/api.php index c9c835d..eb9d26c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,6 +18,22 @@ | */ +Route::get('robots.txt', function () { + $subdomain = \Illuminate\Support\Arr::first(explode('.', request()->getHost())); + + $robotsFile = public_path('robots-api.txt'); + + if ($subdomain === 'admin') { + $robotsFile = public_path('robots-admin.txt'); + } + + return response( + file_get_contents( + $robotsFile + ), 200) + ->header('Content-Type', 'text/plain'); +}); + Route::domain(config('app.url'))->group(function () { Route::get('cache', function() { $cache = Cache::first(); @@ -29,5 +45,4 @@ Route::post('send-email', [MailController::class, 'sendEmail']); Route::get('settings', [PageController::class, 'getSettings']); Route::get('{slug}', [PageController::class, 'show']); - });