【问题标题】:Block all user-agents by htaccess except one通过 htaccess 阻止所有用户代理,除了一个
【发布时间】:2015-06-21 17:22:11
【问题描述】:

我有一个 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 上起作用?

【问题讨论】:

标签: regex apache .htaccess mod-rewrite litespeed


【解决方案1】:

很遗憾,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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2019-05-02
    相关资源
    最近更新 更多