0

I have a htaccess rewrite rule code which works on Apache but not on litespeed.

<Files "bg.js">
SetEnvIfNoCase User-Agent .*autoit.* search_robot
Order Deny,Allow
Deny from All
Allow from env=search_robot
</Files>

I want to block all useragents except those that are a case insensitive match to autoit.

How do I get the rewrite rule to work on litespeed?

max
  • 96,212
  • 14
  • 104
  • 165
  • You can use my rewrite rules for bad User-Agents and Referrers here - https://github.com/mitchellkrogza/apache-ultimate-bad-bot-blocker/tree/master/OpenLitespeed_htaccess – MitchellK Sep 29 '21 at 12:10

1 Answers1

3

Unfortunately, LiteSpeed does not support SetEnvIf* directives in .htaccess files. As an alternative, you'll need to use mod_rewrite:

RewriteEngine On

# Check that the request is for /bg.js
RewriteCond %{REQUEST_URI} ^/bg.js

# Check that the request matches an existing file
RewriteCond %{REQUEST_FILENAME} -f

# Check that the user agent does not contain autoit
RewriteCond %{HTTP_USER_AGENT} !autoit

# If all conditions above are met, then deny access to this request
RewriteRule ^ - [F,L]
Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81