我想阻止空的用户代理,但是在网站的脚本中,有一些片段使用file_get_contents函数,这也会被阻塞。我试图在file_get_contents中添加标题,但这并不好。所以我试着用htaccess绕过本地主机。
以下是htaccess中的规则:
#Block empty User-Agents
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{HTTP_HOST} !^http://(.*\.)?example\.com [NC]
RewriteRule ^ - [F]但它行不通。我该怎么换呢?提前谢谢。
发布于 2016-02-25 23:15:15
经过几次编辑和测试之后,我让它工作了:
#Block empty User-Agents
RewriteCond %{HTTP_USER_AGENT} ^-?$ [NC]
RewriteCond %{HTTP_HOST} !^http://(.*\.)?example\.com [NC]
RewriteCond %{REQUEST_URI} !^/url [NC]
RewriteRule ^ - [F]也曾尝试过:
#RewriteCond %{HTTP_HOST} !^(127\.0\.0\.1|localhost) [NC]
#RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1帮不上忙。只有REQUEST_URI才能工作。
https://stackoverflow.com/questions/35639689
复制相似问题