Redirecting Hotlinked images with Low Resolution versions

↘锁芯ラ 提交于 2019-12-08 09:39:01

问题


i am working on website of a Digital Gadgets Manufacturer. Product images are hotlinked from hundreds of blogs & forums. which is causing bandwidth issues.

we want to replace all hotlinked images with their low resolution versions, using .htaccess

means if the hotlinked image path is

http://www.example.com/products/gadget123/gadget123.png

we want to redirect it to

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

hotlinked image paths are different, means they may be from sub-directory of any directory.

for example

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

etc...

but all low resolution images will be in

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

directory, and their names will be same as their high resolution versions.


回答1:


Try to addopt this:

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(.*?)example\.com(/.*)?$ [NC]
RewriteRule   ^images/products/.+/(.+).png$ images/low-res/$1.png  [L]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(.*?)example\.com(/.*)?$ [NC]
RewriteRule   ^images/products/.+/(.+).png$ images/low-res/$1.png  [L]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(.*?)example\.com(/.*)?$ [NC]
RewriteRule   ^downloads/brochures/.+/(.+).jpg$ images/low-res/$1.jpg  [L]

This rules looking for if the request comes from your site or directly from a third party. And rewrites then the request.



来源:https://stackoverflow.com/questions/14099965/redirecting-hotlinked-images-with-low-resolution-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!