0

我已经在 htaccess 中尝试了以下代码来阻止我的图像被热链接,但它不起作用。

SetEnvIfNoCase Referer "^http://www.example.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://www.example.comm$" locally_linked=1
SetEnvIfNoCase Referer "^http://example.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://example.com$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpe?g|css|js)$">
  Order Allow,Deny
  Allow from env=locally_linked=1
</FilesMatch>

谁能帮助我如何防止盗链?

4

2 回答 2

2

这将在其热链接时显示固定图像。(该图像可能有一条消息,不允许进行盗链...)

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

它检查 Refererr 不是什么都没有,并且 referer 与 mydomain 不匹配,然后它以 image 响应nohotlink.jpg

要更好地了解防盗链,请参阅这些 SO 线程:
Apache .htaccess hotlinking redirect
Apache Hotlink Protection for Download Folder
A Basic tutorial http://altlab.com/htaccess_tutorial.html

于 2012-09-07T20:30:49.197 回答
0

除非引用者来自example.com.

SetEnvIf Referer example\.com localreferer
<FilesMatch \.(jpg|png|gif|css|js|pdf|doc|xls|txt)$>
    Order deny,allow
    Deny from all
    Allow from env=localreferer
</FilesMatch>
于 2013-05-01T04:00:13.220 回答