By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
10alert.com10alert.com10alert.com
  • Threats
    • WordPress ThreatsDanger
    Threats
    A cyber or cybersecurity threat is a malicious act that seeks to damage data, steal data, or disrupt digital life in general. Cyber threats include…
    Show More
    Top News
    An Android that robbed your bank account -Kaspersky Daily
    12 months ago
    New CryptoLocker-like Malware for Android
    12 months ago
    Apple Watch And The Other Smartwatches
    12 months ago
    Latest News
    Beware of scammers! Dangerous apps in the App Store
    6 hours ago
    How To Limit Login Attempts on WordPress (+ Should You?)
    1 day ago
    Wordfence Intelligence Weekly WordPress Vulnerability Report (September 18, 2023 to September 24, 2023)
    1 day ago
    Two privilege escalation vulnerability in Simple Membership Plugin
    2 days ago
  • Fix
    Fix
    Troubleshooting guide you need when errors, bugs or technical glitches might ruin your digital experience.
    Show More
    Top News
    How To Configure Cloudflare To Maximize WordPress Speed + Security
    11 months ago
    Windows 11 build 25179 rolls out in the Dev Channel
    12 months ago
    How to set a static IP address on Windows 11
    12 months ago
    Latest News
    How automatically delete unused files from my Downloads folder?
    8 months ago
    Now you can speed up any video in your browser
    8 months ago
    How to restore access to a file after EFS or view it on another computer?
    8 months ago
    18 Proven Tips to Speed Up Your WordPress Site and Improve SEO | 2023 Guide
    9 months ago
  • How To
    How ToShow More
    Cloudflare now uses post-quantum cryptography to talk to your origin server
    Cloudflare now uses post-quantum cryptography to talk to your origin server
    9 hours ago
    Privacy-preserving measurement and machine learning
    Privacy-preserving measurement and machine learning
    9 hours ago
    Encrypted Client Hello – the last puzzle piece to privacy
    Encrypted Client Hello – the last puzzle piece to privacy
    9 hours ago
    Reminder: Enable two-factor authentication wherever you have it. This business
    13 hours ago
    ​​Know exactly when your data is transferred to GoogleIn a world where our data is permanent
    13 hours ago
  • News
    News
    This category of resources includes the latest technology news and updates, covering a wide range of topics and innovations in the tech industry. From new…
    Show More
    Top News
    How to remove bulk app download notification on iOS?
    12 months ago
    Bug with views
    12 months ago
    How many horns does a unicorn have?
    12 months ago
    Latest News
    How to enable extensions for Google Bard AI
    7 hours ago
    Window 11 Copilot: 10 Best tips and tricks
    14 hours ago
    How to create AI images with Cocreator on Paint for Windows 11
    2 days ago
    How to install September 2023 update with 23H2 features for Windows 11
    3 days ago
  • Glossary
  • My Bookmarks
Reading: How To Prevent Image Hotlinking in WordPress
Share
Notification Show More
Aa
Aa
10alert.com10alert.com
  • Threats
  • Fix
  • How To
  • News
  • Glossary
  • My Bookmarks
  • Threats
    • WordPress ThreatsDanger
  • Fix
  • How To
  • News
  • Glossary
  • My Bookmarks
Follow US
Wordpress Threats

How To Prevent Image Hotlinking in WordPress

Vitus White
Last updated: 28 July
Vitus White 2 months ago
Share
9 Min Read

This blog post explains what is Hotlinking in WordPress.

Contents
What is hotlinking?How hotlinking in WordPress happens?Why hotlinking prevention is important?Methods to prevent hotlinking in WordPressMethod 1: Adding rules into Apache (.htaccess) or Nginx config files Method 2: Using Cloudflare to block site scrapingPrevent hotlinking in your WordPress website

What is hotlinking?

Hotlinking is also known as inline linking or remote linking.

In simpler terms, it means displaying images, videos, gifs, and other media files on a website by linking to the images originating server. 

While it may seem harmless at first, hotlinking can have several adverse effects on your website’s performance and costs.

When another website hotlinks to your images, it steals your bandwidth, making your website slower for visitors and increasing your hosting costs (if paying per gigabyte). Moreover, hotlinking can lead to copyright issues and negatively impact your search engine optimization (SEO) ranking.

If you feel your website images are being hotlink, then it is a good idea to disable the ability to hotlink to your website entirely.

In this tutorial, we will show you two ways to disable hotlinking. 

How hotlinking in WordPress happens?

Hotlinking occurs when a website uses an image or media file that is hosted on another website’s server.

For example, let’s say you run a WordPress blog with photos of your recent holiday adventures. Someone else likes the photos that you have taken and decides to use them on their own website. They will use it by directly using the source URL of the image from your website, without downloading and re-uploading on their own website. This creates a link that is referred to as “Hotlinking”. 

Now whenever the other website receives traffic on the post with an image hotlinked from your website, it will start costing you server bandwidth because images will be served through your hosting. 

The problem with hotlinking is that it can cause the original website’s server to slow down (especially on shared hosting environments) if there are a significant number of requests coming in for the same image. Additionally, hotlinking can be a violation of copyright in some cases and can lead to legal issues.

Why hotlinking prevention is important?

To summarize the reasons you should consider preventing hotlinking on your WordPress website are as follows:

  • Prevent overuse and misuse of your server bandwidth.

Trust us, you don’t want to wake up one day with a notice from your hosting provider that says that you are being charged hundreds of dollars more as bandwidth overages. 

  • Reduction in website performance. 

Even if you stay within your bandwidth allocation, it is best to disable hotlinking because repeated requests from third-party websites could slow your website down.

You might buy your images from marketplaces and use them on your website and someone else might hotlink and use them on their website, and it can cause a copyright infringement if the license doesn’t allow the image to be used on multiple websites.

If somebody else uses your images and Google values their website more than yours, the visibility of your website in Google Images will be reduced. It can also cause duplication issues, and both sites will be negatively affected. 

Methods to prevent hotlinking in WordPress

There are several methods to prevent hotlinking in WordPress websites. Let’s look into two options.

Method 1: Adding rules into Apache (.htaccess) or Nginx config files 

.htaccess rules for blocking hotlinking

You can manually disable hotlinking if you are hosting your WordPress website that uses an Apache server. 

You will need to add the following lines of code in your .htaccess file, which is usually found in the public_html folder.

Before you make the edit, it is better to keep a backup of your .htaccess file. 

/* Prevent image hotlinking in WordPress */
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourwebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?twitter.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?other-websites-if-any.com [NC]
RewriteRule .(jpg|jpeg|png|gif)$ - [F]

Here’s what the rule does:

  • The first line checks if the HTTP Referer header is not empty.
  • The next few lines check if the HTTP Referer header does not match the allowed domains. In this case, the domains that are allowed to hotlink your images are yourwebsite.com, google.com, facebook.com, twitter.com, and other-websites-if-any.com. The [NC] flag makes the condition case-insensitive.
  • The last line specifies the types of files that should be blocked from hotlinking. In this case, it’s .jpg, .jpeg, .png, and .gif files. The -[F] flag returns a 403 Forbidden response to the client if the conditions are met.

So, any requests for hotlinked images from domains other than the ones specified will be blocked with a 403 Forbidden error. 

Nginx config file rules for blocking hotlinking

If you are hosting on a Nginx-based server then you will need to add the following rules in the config file to block hotlinking. 

location ~ .(gif|png|jpeg|jpg|svg)$ {
     valid_referers none blocked ~.google. ~.bing. ~.yandex. ~.yahoo. mydomain.com *.mydomain.com;
     if ($invalid_referer) {
        return   403;
    }
}

Here’s how the above code works:

  • The location block matches any requests for files with extensions .gif, .png, or .jpeg/jpg.
  • The valid_referers directive specifies the domains allowed to refer to the files. In this case, none and block are used to prevent any referrers from the same domain or blocked referrers. mydomain.com and *.mydomain.com allow requests from the domain and its subdomains; you can replace mydomain with your own website URL.
  • The if statement checks if the referer is invalid. If the request comes from an invalid referer, the server responds with a 403 Forbidden status code.

This rule prevents other websites from displaying your images directly by hotlinking them. It is a good way to protect your image resources and prevent other websites from using your website’s bandwidth, which can affect your website’s speed and performance.

Method 2: Using Cloudflare to block site scraping

Cloudflare is a popular choice amongst WordPress website creators to use as CDN and improve WordPress site security. 

One little-known feature of Cloudflare is to use it to disallow hotlinking on your website. Once you have configured Cloudflare on your WordPress website, you can disable hotlinking under the option called “Scrape Shield” 

Hotlinking in WordPress

By default, enabling this rule will block all hotlinks from all search engines and websites other than your own. You can customize the rules by following the guidelines in Cloudflare documentation.

Prevent hotlinking in your WordPress website

Preventing hotlinking is especially useful for websites that have a lot of media content, like images and videos. People can easily link to the media hosted on your server, causing your server’s performance to degrade and costing you a lot of bandwidth. 

The methods highlighted in this tutorial are the easiest and sure ways to prevent hotlinking on your WordPress websites. Be sure to allow search engines and social media sites to use your images; if you disallow them, it may cause your rankings to suffer and images do not appear on your social channels.


Source: patchstack.com

Translate this article

TAGGED: DoS, Security, Threats, WordPress
Vitus White July 28, 2023 July 28, 2023
Share This Article
Facebook Twitter Reddit Telegram Email Copy Link Print

STAY CONECTED

24.8k Followers Like
253.9k Followers Follow
33.7k Subscribers Subscribe
124.8k Members Follow

LAST 10 ALERT

Cloudflare now uses post-quantum cryptography to talk to your origin server
Cloudflare now uses post-quantum cryptography to talk to your origin server
Apps 9 hours ago
Privacy-preserving measurement and machine learning
Privacy-preserving measurement and machine learning
Apps 9 hours ago
Encrypted Client Hello – the last puzzle piece to privacy
Encrypted Client Hello – the last puzzle piece to privacy
Apps 9 hours ago
Beware of scammers! Dangerous apps in the App Store
Threats 9 hours ago
How to enable extensions for Google Bard AI
News 10 hours ago

You Might Also Like

Cloudflare now uses post-quantum cryptography to talk to your origin server
Apps

Cloudflare now uses post-quantum cryptography to talk to your origin server

9 hours ago
Privacy-preserving measurement and machine learning
Apps

Privacy-preserving measurement and machine learning

9 hours ago
Encrypted Client Hello – the last puzzle piece to privacy
Apps

Encrypted Client Hello – the last puzzle piece to privacy

9 hours ago
Threats

Beware of scammers! Dangerous apps in the App Store

9 hours ago
Show More

Related stories

How to upgrade to Windows 11 23H2 with Installation Assistant
How to install September 2023 update with 23H2 features for Windows 11
Critical Vulnerability in Forminator Plugin
How to get the latest Windows 11 innovations
How to blur image background in Photos for Windows 11
How to download official Windows 11 23H2 ISO file
Previous Next

10 New Stories

Reminder: Enable two-factor authentication wherever you have it. This business
​​Know exactly when your data is transferred to GoogleIn a world where our data is permanent
​​Fake correspondence with the iPhone interfaceIn a world where digital communication is
​​Let's find out who is watching your Instagram stories from a fake Have you ever wondered
Window 11 Copilot: 10 Best tips and tricks
How To Limit Login Attempts on WordPress (+ Should You?)
Previous Next
Hot News
Cloudflare now uses post-quantum cryptography to talk to your origin server
Privacy-preserving measurement and machine learning
Encrypted Client Hello – the last puzzle piece to privacy
Beware of scammers! Dangerous apps in the App Store
How to enable extensions for Google Bard AI
10alert.com10alert.com
Follow US
© 10 Alert Network. All Rights Reserved.
  • Privacy Policy
  • Contact
  • Customize Interests
  • My Bookmarks
  • Glossary
Go to mobile version
adbanner
AdBlock Detected
Our site is an advertising supported site. Please whitelist to support our site.
Okay, I'll Whitelist
Welcome Back!

Sign in to your account

Lost your password?