允许/拒绝使用 .htaccess 进行图像热链接
所以我在我的网站 .htaccess 文件中添加了这个,以防止来自所有其他域的图像、JS 和 CSS 的热链接。
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]
问题:我如何有选择地允许一两个域进行热链接?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在您要允许的每个域的 RewriteRule 之前添加另一个条件即可。
(大概你不关心请求是通过http还是https还是其他方式,所以你可以忽略它以使其更通用)
Just add another condition before the RewriteRule for each domain you want to allow.
(presumably you don't care if the request is via http or https or whatever, so you can leave that out to make it more generic)
正如这句话所说,会起作用的。
“Refererr 并不是什么都不是,Referer 与 mydomain 不匹配,Referer 与 otherdomain 不匹配。
如果您试图执行相反的操作(将一组域列入黑名单,防止热链接),您会执行类似的操作
Will work, as this says.
"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