重写所有图像和一个特定的 php 文件名
作为防止热链接的预防措施,我一直在使用以下规则将错误引用者重定向到我们的徽标而不是实际图像:
#Naughty hotlinkers
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) assets/hotlinked/logo.jpg [L]
对于图像来说,它效果很好。
我正在编写可怕的包装代码,以保留嵌入在用户内容中的图像,其 src 指向一个 php 文件,该文件用于过滤请求并为我们的图像提供服务。尽管新图像将不再以这种方式提供,但我们确实需要确保以前上传的图像仍然可以从旧地址获取。
尽管图像仍然需要可访问,但该文件也需要防止热链接。
我试过这个:
#Naughty hotlinkers
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*gp2\.php.* [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) assets/hotlinked/logo.jpg [L]
但没有骰子。
我想要保护的文件在图像的 src 中使用,例如:
http://sitedomain/legacy/gp2.php?p=long_stupid_string
请 apache 大师告诉我我在这里做错了什么愚蠢的事情?
编辑:
我在这里测试热链接预防:(
图片)这里
(php)这里
As a precaution against hotlinking, I've been using the following rule to redirect people with the wrong referrer to our logo instead of the actual image:
#Naughty hotlinkers
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) assets/hotlinked/logo.jpg [L]
It works well, for images.
I'm in the process of writing horrible wrapping code to preserve images embedded in our user's content with their src pointing to a php file that was used to filter requests for and serve our images. Although new images will no longer be served this way, we do need to ensure previously uploaded images are still available from their old address.
Though the images still need to be accessible, this file needs to be guarded against hotlinking as well.
I tried this:
#Naughty hotlinkers
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*gp2\.php.* [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !sitedomain\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) assets/hotlinked/logo.jpg [L]
But no dice.
The file I want to protect used in image's src like:
http://sitedomain/legacy/gp2.php?p=long_stupid_string
Please will an apache guru tell me what stupid thing I'm doing wrong here?
Edit:
I'm testing hotlink prevention here:
(image) here
(php) and here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案
Solution