使用 .htaccess 允许/拒绝图像盗链 [英] Allow/deny image hotlinking with .htaccess

查看:24
本文介绍了使用 .htaccess 允许/拒绝图像盗链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的站点 .htaccess 文件中有这个,以防止盗链来自所有其他域的图像、JS 和 CSS.

So I've got this in my site .htaccess file to prevent hotlinking of images, JS and CSS from all other domains.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.com [NC]
RewriteRule .(gif|jpe?g|js|css)$ - [F,NC,L]

问题:我如何有选择地允许一两个域进行盗链?

Question: How would I selectively allow one or two domains to hotlink?

推荐答案

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?otherdomain.com [NC]
RewriteRule .(gif|jpe?g|js|css)$ - [F,NC,L]

会起作用,正如上面所说.

Will work, as this says.

Refererr 不是什么都没有,而且referer 不匹配mydomain 并且referer 不匹配otherdomain.

"Refererr is not nothing, and referer is not matching mydomain and referer is not matching otherdomain.

如果您试图做相反的事情(将一组域名列入盗链黑名单),您会做类似的事情

If it were the case that you were trying to do the opposite (blacklist a set of domains from hotlinking) you'd do something like

RewriteCond %{HTTP_REFERER} ^http://(www.)?baddomain1.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www.)?baddomain2.com [NC]
RewriteRule .(gif|jpe?g|js|css)$ - [F,NC,L]

这篇关于使用 .htaccess 允许/拒绝图像盗链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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