How to prevent image hotlinking in WordPress

How to prevent image hotlinking in WordPress

Then add the following commands.

What to do to stop image hotlinking from your website

Your website is called yourwebsite.com. In order to stop hotlinking to images on your website, and instead of all images on all foreign sites, show the image that is on a free photo hosting, for example, flickr.com at – https://farm9.staticflickr.com/8239/ 8610809796_8e022cd190_d.jpg), paste the following piece of code into the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https://(.+\.)?yourwebsite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ https://farm9.staticflickr.com/8239/8610809796_8e022cd190_d.jpg [L]

The first line of code includes the rewrite function. The second line blocks the url of any foreign sites except svojblog.com. You simply copy the third line. The fourth line defines and replaces all jpeg, jpg, gif, bmp, png image files with the image located at https://farm9.staticflickr.com/8239/8610809796_8e022cd190_d.jpg.

Or you can specify the path to the image that is on your site, something like “image has been taken from yourwebsite.com”. Just create a small image so that the server does not overload. In any case, it is better to use a free photo hosting like flickr.com.

Hotlinking images and 403 error

You can also show a 403 error instead of a picture. I do not really recommend this, it is better to insert a mention of your blog in the image on a free hosting. For 403 errors, use the code:

RewriteRule .*\.(jpe?g|gif|bmp|png)$ — [F]

Remember also that using .htaccess to redirect images to another HTML page or server is not just an image.

So, I hope this lesson will help stop the “soulless” use of your hosting resources!

// discussion

No comments yet — be the first

Leave a comment

// your email stays private. Required fields marked with an asterisk.