WordPress: How to Prevent Image Hotlinking

WordPress How to Prevent Image Hotlinking

Hosting your WordPress website on your Synology NAS brings hosting costs to zero. Today I will teach you how to prevent image hotlinking on your WordPress website hosted on your Synology NAS. First of all, image hotlinking is when someone embeds your images on their website by linking them directly from your website. This can slow down your WordPress website. Each time someone views a hotlinked image on a different website, it’s still loading from your Synology NAS server. What does this mean? This means they’re consuming your Internet bandwidth without even visiting your WordPress site.

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Back up your .htaccess file.

  • STEP 3

Go to your WordPress folder then open and edit the .htaccess file by adding the code below at the beginning of your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YOURDOMAIN.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?ecosia.org [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?duckduckgo.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?baidu.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?qwant.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yandex.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?reddit.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?pinterest.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?twitter.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|svg|webp)$ https://image.prntscr.com/image/WeQVsF-JQ7KCcyQG8AqcbQ.png [NC,R,L]
  • STEP 4

Your .htaccess file should look like the one presented in the image below.
Note: If you have other codes before #BEGIN WordPress, do not delete them. Insert the code I have provided to you above, at the beginning of all other codes.

htaccess file synology Hotlinking protection

  • STEP 5

Note: In the code above remember to change YOURDOMAIN.com with your own domain name.
Note: In the code above, the other domains under your main domain name, for example, Google, Bing, Yahoo, Ecosia, DuckDuckGo, Baidu, Reddit, Pinterest, Facebook, Twitter are currently whitelisted and they can access your images without problem.
Note: In the code above the last line indicates which file formats you’ll apply the hotlink prevention rule to and a redirect towards an image link hosted elsewhere like the one below:

  • STEP 6

Example of the code in action. I have hotlinked some images from mariushosting and posted them on my test website. As you can see in the image below, the 3 images I have linked from mariushosting are redirected to the one I have previously added in the last line of the code.

WordPress Synology NAS image hotlinking

Is there any method to find out if someone is hotlinking your WordPress images? In most cases, you may not realize someone is hotlinking your images until you start to see a reduction in your Synology WordPress website performance. Today I will teach you a second method to find hotlinked images: go to Google images then add the line below in the search field:

inurl:yourdomain.com -site:yourdomain.com

Google search image hotlinking protection Synology NAS

Note: remember to change yourdomain.com with your own domain name.

This post was updated on Wednesday / November 11th, 2020 at 3:49 PM