1 year ago

How to prevent image hotlinking in WordPress

Today is a short post about a problem that arose on my website, where I posted a lot of pictures.…

Today is a short post about a problem that arose on my website, where I posted a lot of pictures. My pictures began to brazenly steal, moreover, not upload to your server, but downloading from mine. The server load increased, the server sometimes on began to fall down for a while. This process is called hotlinking.
How to prevent image hotlinking in WordPress
I decided to make changes to the .htaccess file. The .htaccess file is on almost every hosting, if you do not, then create it. If you have difficulty with this, then contact the hosting company that serves your hosting, they will help to create this file.

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!

Leave a Reply

Your email address will not be published. Required fields are marked*