盗链保护,正确的.htaccess规则? [英] Hotlink protection, correct .htaccess rules?

查看:117
本文介绍了盗链保护,正确的.htaccess规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到许多博客的,也很多答案在这里在让人们使用这种code做防盗链:

  RewriteEngine叙述上
的RewriteCond%{HTTP_REFERER}!^ $
的RewriteCond%{HTTP_REFERER} ^ HTTP(S):??//(WWW \)mydomain.com [NC]
重写规则\。(JPG | JPEG | PNG | GIF)$  -  [NC,F,L]
 

这也是由建议这个工具

我可能是错的,但是不是琐碎的欺骗这个code?不刮刀只需要使用一个简单的子域这样的那些绕过防盗链?

  http://mydomain.com.scarper1domain.com
http://mydomain.com.scraper2domain.net
 


编辑:仅供参考我用这个code,我觉得是比较防弹的,但我很乐意阅读您的意见/批评一下吧

  RewriteEngine叙述上
的RewriteCond%{HTTP_REFERER}!^ $
的RewriteCond%{HTTP_REFERER} ^ HTTP(S):!?(WWW \)?// MYDOMAIN \ .COM /.*$ [NC]
的RewriteCond%{HTTP_REFERER} ^ HTTP(S):!?(WWW \)?// MYDOMAIN \ .COM $ [NC]
重写规则* \。(JPG | JPEG | PNG | GIF)$  -  [F,NC,L]
 

解决方案

由于大部分的Apache设置已经重定向如example.com请求example.com/~~V,就没有必要在你的编辑第三个条件。因此,code将成为

  RewriteEngine叙述上
的RewriteCond%{HTTP_REFERER}!^ $
的RewriteCond%{HTTP_REFERER} ^ HTTP(S):!?(WWW \)?// MYDOMAIN \ .COM /.*$ [NC]
重写规则* \。(JPG | JPEG | PNG | GIF)$  -  [F,NC,L]
 

铲运机甚至不需要使用子域名,因为它们可以被发送只不过是假的HTTP标头。没办法,prevent这一点。

的code剩下的就是好的。我会用这个,如果我需要它。

I saw on many blogs and also on many answers here on SO that people do Hotlink protection by using this code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

which is also suggested by this tool.

I might be wrong, but isn't it trivial to trick this code? Doesn't a scraper simply need to use a simple subdomains like these ones to bypass the hotlink protection?

http://mydomain.com.scarper1domain.com
http://mydomain.com.scraper2domain.net


EDIT: FYI I use this code that I think is more bulletproof, but i'm happy to read your comments/critics about it.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.com$ [NC]
RewriteRule .*\.(jpg|jpeg|png|gif)$ - [F,NC,L]

解决方案

As most apache setups already redirect requests like example.com to example.com/, there is no need for the third condition in your edit. So the code would become

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.com/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|png|gif)$ - [F,NC,L]

Scrapers don't even need to use subdomains, as they can just fake the http headers being sent. No way to prevent this.

The rest of the code is okay. I would use this if I needed it.

这篇关于盗链保护,正确的.htaccess规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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