.htaccess 允许所有来自特定用户代理 [英] .htaccess Allow All from Specific User Agent

查看:32
本文介绍了.htaccess 允许所有来自特定用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,该网站也将被拉入网络应用程序.我的 .htaccess 文件中有以下代码,以防止任何不在我允许的 IP 上的人访问:

I have a website I am developing that is also going to be pulled into a web app. I have the following code in my .htaccess file to prevent access from ANYONE that is not on my allowed IP:

Order deny,allow
Deny from all
AuthName "Restricted Area - Authorization Required" 
AuthUserFile /home/content/html/.htpasswd 
AuthType Basic
Require valid-user
Allow from 12.34.567.89 
Satisfy Any

问题:我想添加一个 Allow from 规则,该规则还允许特定的 HTTP 用户代理访问该站点.

QUESTION: I would like to add an Allow from rule that will ALSO allow a specific HTTP user agent access to the site.

如果不是用户代理,我发现此代码可以重定向:

I found this code to redirect if not the user agent:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !=myuseragent
RewriteRule ^files/.*$ / [R=302,L]

但我似乎无法弄清楚如何将其转换为 Allow from 规则.有帮助吗?

But I can't seem to figure out how to turn this into an Allow from rule. Help?

更新

我发现下面的代码可以阻止特定的用户代理...我想说如果不是 myuseragent,则阻止."

I found the code below to block specific user agents... I would instead like to say "if NOT myuseragent, then block."

<IfModule mod_rewrite.c>
SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
Deny from env=HTTP_SAFE_BADBOT
</ifModule>

推荐答案

SetEnvIfNoCase User-Agent .*google.* search_robot
SetEnvIfNoCase User-Agent .*yahoo.* search_robot
SetEnvIfNoCase User-Agent .*bot.* search_robot
SetEnvIfNoCase User-Agent .*ask.* search_robot

Order Deny,Allow
Deny from All
Allow from env=search_robot

Htaccess SetEnvIf 和 SetEnvIfNoCase 示例

这篇关于.htaccess 允许所有来自特定用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆