You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP图片防盗链(hotlink)与.htaccess配置失效问题排查

盗链图片水印PHP脚本失效问题

问题详情

  • 实现了一套针对盗链图片添加水印的PHP脚本,直接访问http://www.example.com/watermark.php?path=http://www.example.com/photos/image.jpg时,能正常输出带水印的图片,但通过.htaccess规则触发跳转时,始终显示原始图片,判断问题出在.htaccess配置中。
  • 为排除PHP脚本本身的问题,曾在脚本中添加固定输出指定图片的代码,结果问题依旧,确认PHP脚本无异常。

当前.htaccess配置代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !example\.com [NC] 
RewriteCond %{HTTP_REFERER} !google\. [NC] 
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) watermark.php?path=$1
#or RewriteRule (.*) /watermark.php?path=$1

用于测试的PHP代码片段

header('Content-type: image/jpg');
readfile('images/sun.jpg');

内容的提问来源于stack exchange,提问作者iBison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 07:25:24