Redirecting Hotlinked images with Low Resolution v

2019-06-09 12:25发布

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条回答
对你真心纯属浪费
2楼-- · 2019-06-09 13:17

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.

查看更多
登录 后发表回答