Home  >  Article  >  Backend Development  >  关于图片防盗链有关问题

关于图片防盗链有关问题

WBOY
WBOYOriginal
2016-06-13 12:04:33998browse

关于图片防盗链问题
测试地址是:http://127.0.0.2/test.html

<body><img  src="./11.png" alt="关于图片防盗链有关问题" ></body>

.htaccess
<br />RewriteEngine on<br />RewriteCond %{HTTP_REFERER} ^http://127.0.0.2/.*$ [NC]<br />RewriteRule .*\.(gif|jpg|png)$ http://127.0.0.2/22.jpg [R,NC]<br />


来自本站的图片全部定向到22.jpg去,但上面这么写不能显示图片。
在chrome下测试,总共有23次Request,其中test.html和11.png各一次;22.jpg这张图21次,前20次状态码都是302 found,最后一次是下面截图这样:


为什么是这样?
------解决方案--------------------
死循環重定向了。
防盜鏈應該不是自己站點的域名才需要跳轉到22.jpg,而自己站點的則不需要跳轉才對啊。

改成這樣試試
<br />RewriteCond %{HTTP_REFERER} !^$ <br />RewriteCond %{HTTP_REFERER} !^http://127\.0\.0\.2/.*$ [NC] <br />RewriteRule \.(gif<br><font color='#FF8000'>------解决方案--------------------</font><br>jpg<br><font color='#FF8000'>------解决方案--------------------</font><br>png)$ http://127.0.0.2/22.jpg [R=301,L] <br />

------解决方案--------------------
http://127.0.0.2/22.jpg 也會匹配^http://127.0.0.2/.*$ 所以會死循環
如果想不死循環,
http://127.0.0.2/22.jpg [R,NC] 改成 [R=301,L] 試試
------解决方案--------------------
死循环  要防盗链的图片放在目录里面  设置那个目录就可以了 你这样设置所有的图片  又重定向到另外的图片  这不是自己玩自己吗?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn