Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top