Inline list of bad bots to block in .htaccess

This commit is contained in:
Helen Chong 2024-10-05 16:18:35 +08:00
parent 346398e85a
commit a4b7b723e7
2 changed files with 3 additions and 5 deletions

View File

@ -15,7 +15,5 @@ Header set Cache-Control "no-cache, public"
RewriteEngine on RewriteEngine on
# Block bad bots # Block bad bots
{% for bot in robots.htaccess -%} RewriteCond %{HTTP_USER_AGENT} ({{ robots.htaccess }}) [NC]
RewriteCond %{HTTP_USER_AGENT} ({{ bot | replace(" ", ".*") }}) [NC{% if not loop.last %},OR{% endif %}]
{% endfor -%}
RewriteRule .* https://nocommercialuse.org/ [L] RewriteRule .* https://nocommercialuse.org/ [L]

View File

@ -23,10 +23,10 @@ export default async function () {
line !== "User-agent: Applebot" line !== "User-agent: Applebot"
); );
}) })
.map((line) => line.split(":")[1].trim()); .map((line) => line.split(":")[1].trim().replace(/\s/gi, ".*"));
return { return {
txt: txt, txt: txt,
htaccess: bots, htaccess: bots.join('|'),
}; };
} }