feat(bots.php, htaccess.liquid): share files with specific bots
This commit is contained in:
parent
79464d6769
commit
92e123cd57
6 changed files with 66 additions and 18 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue