问题原文
原帖链接 · seefah · CC BY-SA 4.0
I have the following in my .htaccess file on website2, but when my other website on website1 makes requests to website2 it is blocked because the server user-agent is blank.
Is there are a way to allow a single IP address into the code below, or some other method to block the empty user-agent bots but allow my website1 to make requests to files on website2?
SetEnvIfNoCase User-Agent ^$ bad_bot #leave this for blank user-agents
SetEnvIfNoCase User-Agent "^more-bad-bots" bad_bot
<Limit GET POST HEAD>
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</Limit>
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
... because the server user-agent is blank.
Why not set a user-agent in your script? You shouldn't be making HTTP requests with blank user-agents. (If using PHP then this may be as simple as calling ini_set('user_agent','my-user-agent'))
Is there a way to allow a single IP address
You can unset the bad_bot environment variable if the requesting IP is known. For example:
# Leave this for blank user-agents
SetEnvIfNoCase User-Agent ^$ bad_bot
SetEnvIfNoCase User-Agent "^more-bad-bots" bad_bot
# Unset bad_bot if request is from 203.0.113.111
SetEnvIf Remote_Addr ^203\.0\.113\.111$ !bad_bot
:
I've also removed your line-end comment - Apache does not support them! That "line-end comment" was setting 5 additional environment variables: #leave, this, for, blank and user-agents!
Apache only supports full-line comments.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
