How to Enable Hotlink Protection for WebP Images in OpenLiteSpeed

#1
Hi,

I’d like to know how to apply hotlink protection in OpenLiteSpeed specifically for WebP images. I’ve noticed that other websites are using images hosted on my site, and I want to block that.

At the same time, I don’t want this to affect Pinterest’s bot (I assume it may not be related, but just in case).

What would be the correct way to set this up in OpenLiteSpeed?

Thanks!
 
#2
Hi,

How about placing these example rules in your .htaccess file?

Code:
RewriteCond %{HTTP_REFERER} !https://yourdomain.com [NC]
RewriteCond %{HTTP_REFERER} !www.pinterest.com[NC]
RewriteRule \.(webp)$ - [F,NC,L]
 
#3
Thanks for the example!

If my site uses www, should I include it in the rule as well? Also, this shouldn’t block the Pinterest bot, right?

And if I want to add Bing to the allowed list, how should I write that line?
 
#4
You can also use user-agent to match the bot. You might want to give it a try and modify it.

Code:
RewriteCond %{HTTP_USER_AGENT} !(pinterestbot|bingbot) [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
RewriteRule \.(webp)$ - [F,NC,L]
 
Top