【问题标题】:htaccess prevent hotlinking image specific file name structurehtaccess 防止热链接图像特定的文件名结构
【发布时间】:2016-08-25 08:32:12
【问题描述】:

我在 .htaccess 文件中有以下内容,它工作正常:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg)$ /noimageforyou [NC,R,L]

这可以防止所有图像的热链接。但是,我实际上可以热链接 some 图像。我使用的是 WordPress,当您上传图片时,它会创建各种尺寸的图片,例如:

  • imagefile.jpg(原件)
  • 图像文件-150x150.jpg
  • 图像文件-300x400.jpg

我很高兴允许热链接较小的图像尺寸,而不是原始图像。我想知道是否有一种方法可以改进 htaccess 以像现在一样排除所有内容,然后允许其中包含 #x#.jpg 的任何文件名。

【问题讨论】:

    标签: php wordpress .htaccess


    【解决方案1】:

    您需要添加一个条件来过滤掉较小的图像:

    RewriteEngine on 
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
    RewriteCond %{REQUEST_FILENAME} !-\d+x\d+\.jpg # Check the end of the filename only - we don't need the beginning part for this check
    RewriteRule \.(jpg)$ /noimageforyou [NC,R,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 2012-08-27
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多