feat(bots.php, htaccess.liquid): share files with specific bots

This commit is contained in:
Cory Dransfeldt 2025-05-30 14:54:21 -07:00
parent 79464d6769
commit 92e123cd57
No known key found for this signature in database
6 changed files with 66 additions and 18 deletions

View file

@ -83,23 +83,22 @@ Redirect {{ redirect.status_code | default: "301" }} {{ redirect.source_url }} {
</FilesMatch>
{% endfor %}
{%- assign userAgents = "" -%}
{% for robot in robots -%}
{%- for userAgent in robot.user_agents -%}
{%- if userAgent != "*" and userAgent != "NaN" -%}
{%- assign userAgents = userAgents | append: userAgent %}
{%- unless forloop.last -%}
{%- assign userAgents = userAgents | append: "|" -%}
{%- endunless -%}
{%- assign escapedAgents = "" -%}
{%- for robot in robots -%}
{%- for agent in robot.user_agents -%}
{%- if agent != "*" and agent != "NaN" -%}
{%- assign escaped = agent | regexEscape -%}
{%- assign escapedAgents = escapedAgents | append: escaped | append: "|" -%}
{%- endif -%}
{%- endfor -%}
{%- endfor %}
{% if userAgents != "" or referers != "" -%}
RewriteCond %{HTTP_USER_AGENT} "{{ userAgents }}" [NC]
{%- endfor -%}
{%- assign userAgentsRegex = escapedAgents | slice: 0, escapedAgents.size | rstrip: "|" -%}
{% if userAgentsRegex != "" %}
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "{{ userAgentsRegex }}" [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteRule .* /403/index.html [L,R=403]
{%- endif %}
RewriteRule .* /api/bots.php [L]
{% endif %}
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>