Block all user-agents by htaccess except one

1.7k views Asked by At

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?

1

There are 1 answers

0
Mike Rockétt On BEST ANSWER

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]