Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 用低分辨率版本替换热链接图像_Regex_.htaccess_Mod Rewrite_Redirect_Hotlinking - Fatal编程技术网

Regex 用低分辨率版本替换热链接图像

Regex 用低分辨率版本替换热链接图像,regex,.htaccess,mod-rewrite,redirect,hotlinking,Regex,.htaccess,Mod Rewrite,Redirect,Hotlinking,我在一家数码产品制造商的网站上工作。 产品图片通过数百个博客和论坛进行热链接。这导致了带宽问题 我们希望使用低分辨率版本替换所有热链接图像 .htaccess 表示如果热链接图像路径为 http://www.example.com/products/gadget123/gadget123.png 我们想把它重定向到 http://www.example.com/images/low-res/gadget123.png 热链接图像路径不同,这意味着它们可能来自任何目录的子目录 比如说 /ima

我在一家数码产品制造商的网站上工作。 产品图片通过数百个博客和论坛进行热链接。这导致了带宽问题

我们希望使用低分辨率版本替换所有热链接图像 .htaccess

表示如果热链接图像路径为

http://www.example.com/products/gadget123/gadget123.png
我们想把它重定向到

http://www.example.com/images/low-res/gadget123.png
热链接图像路径不同,这意味着它们可能来自任何目录的子目录

比如说

/images/products/abc/gadget_abc200.jpg
/products/images/abc/gadgetabc5155_packing.png
/downloads/brochures/abc2012/abc2012_user_guide.jpg

etc...
但所有低分辨率的图像都将在

http://www.example.com/images/low-res/

目录,它们的名称将与它们的高分辨率版本相同。

我假设高分辨率和低分辨率图像之间的文件名始终相同,而不考虑原始文件夹

RewriteEngine on
RewriteBase /

RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^(images|products|downloads)/[a-zA-z0-9]+/([a-zA-z0-9]+)(\.jpg|\.png|\.gif)$ images/low-res/$2$3

这至少适用于所提供的示例。如果需要考虑其他子文件夹,则需要相应调整规则。

尝试此操作时会发生什么?