通过htaccess阻止所有用户代理除了一个

问题描述:

我有一个htaccess重写规则代码,它可以在Apache上运行,但不能在litespeed上运行。通过htaccess阻止所有用户代理除了一个

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

我想阻止除那些不区分大小写的匹配autoit所有useragents。

如何让重写规则在litespeed上工作?

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