RewriteEngine on

# NOTE: To enable the antibot challenge for all instances, uncomment the next SetEnvIf line.
# Or enable it per instance by adding the next SetEnvIf line [without comment] to the corresponding virtual host file in /etc/apache2/sites-enabled.
# SetEnvIf Request_URI ^ ANTIBOT_ENABLED=1

RewriteCond %{ENV:ANTIBOT_ENABLED} ^(1|Y|Yes)$
RewriteCond expr "%{REQUEST_URI} =~ m#^/cgi-bin/koha/(opac-detail.pl|opac-export.pl|opac-suggestions.pl|opac-search.pl|opac-authoritiesdetail.pl|opac-ISBDdetail.pl|opac-MARCdetail.pl|opac-shelves.pl)$#"
RewriteCond %{HTTP:Cookie} !(^|;\s*)CGISESSID= [NC]
#NOTE: The KOHA_INIT is set by Javascript by the fast challenge webpage
RewriteCond %{HTTP:Cookie} !(^|;\s*)KOHA_INIT= [NC]
RewriteRule ^ - [E=ANTIBOT_DO:true]

#NOTE: Internal redirect to our challenge page
RewriteCond %{ENV:ANTIBOT_DO} ^true$
RewriteRule ^ /opac-tmpl/lib/koha_fast_challenge/index.html [L,PT]
