From a4b7b723e791d3c2d8c9a624b88f37df558e2c2e Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:18:35 +0800 Subject: [PATCH] Inline list of bad bots to block in .htaccess --- src/.htaccess.njk | 4 +--- src/_data/robots.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/.htaccess.njk b/src/.htaccess.njk index 2b3e8d69..febf04ab 100644 --- a/src/.htaccess.njk +++ b/src/.htaccess.njk @@ -15,7 +15,5 @@ Header set Cache-Control "no-cache, public" RewriteEngine on # Block bad bots -{% for bot in robots.htaccess -%} -RewriteCond %{HTTP_USER_AGENT} ({{ bot | replace(" ", ".*") }}) [NC{% if not loop.last %},OR{% endif %}] -{% endfor -%} +RewriteCond %{HTTP_USER_AGENT} ({{ robots.htaccess }}) [NC] RewriteRule .* https://nocommercialuse.org/ [L] \ No newline at end of file diff --git a/src/_data/robots.js b/src/_data/robots.js index 30cfd807..2ab051c6 100644 --- a/src/_data/robots.js +++ b/src/_data/robots.js @@ -23,10 +23,10 @@ export default async function () { line !== "User-agent: Applebot" ); }) - .map((line) => line.split(":")[1].trim()); + .map((line) => line.split(":")[1].trim().replace(/\s/gi, ".*")); return { txt: txt, - htaccess: bots, + htaccess: bots.join('|'), }; } \ No newline at end of file