阻止除htaccess之外的所有用户代理

时间:2015-06-21 17:22:12

标签: regex apache .htaccess mod-rewrite litespeed

我有一个htaccess重写规则代码,适用于Apache但不适用于litespeed。

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

我想阻止所有使用者,除了那些与autoit不区分大小写的用户。

如何让重写规则适用于litespeed?

1 个答案:

答案 0 :(得分:3)

不幸的是,LiteSpeed不支持SetEnvIf*文件中的.htaccess指令。作为替代方案,您需要使用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]