0

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.

Mudassar Bashir
  • 2,542
  • 2
  • 14
  • 11

1 Answers1

0

I am making the assumption that the filename is always the same between the high and low resolution images regardless of the original folder.

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

This will at least work for the example provided. If there are additional subfolders that need to be taken into account the rule would need to be adapted accordingly.

Wige
  • 3,788
  • 8
  • 37
  • 58