Web hosting

Hotlinking

Definition

Hotlinking (or direct linking) means displaying on one site an image, video or file hosted on another site, by pointing straight to its URL instead of copying it. Every view is then served by the original server, which pays for the bandwidth and load without getting any benefit from the visit.

Hotlinking, Web hosting

To illustrate a page, the easiest shortcut is to paste the URL of an image found elsewhere: <img src="https://your-site.com/wp-content/uploads/photo.jpg">. The image shows up on the other site, but it's your server that sends it, to every one of its visitors. The Apache documentation describes the practice as using your bandwidth to serve content on someone else's site.

How hotlinking works

When a browser loads an image, it usually states the page containing it in the Referer HTTP header. MDN explains that this header may contain the origin, path and query string of the page, depending on the referrer policy in effect. That's what makes it possible to recognize requests coming from other sites.

Hotlinking diagram. Another site inserts an image tag in its page that points to your file. A visitor opens that page. Their browser requests the image from your server, with a Referer header naming the other site's page. Your server sends the image using your bandwidth. A protection rule compares the Referer with a list of allowed sites and can return a 403 error or a replacement image.

Why it matters

  • Bandwidth and server load: a photo reused on a high-traffic page multiplies the requests to your hosting, which hurts on a capped plan or one billed by traffic.
  • Use of your visuals: your work illustrates someone else's site, often without permission or a link back to you.
  • Reputation risk: your file can appear on a shady site, and any change on your end shows up there too.

How to prevent it

Protection relies on the Referer header, with two limitations the Apache and Nginx docs point out: it's optional, so some browsers or privacy settings don't send it, and it's easy to fake. So you have to let requests without a Referer through, and treat this protection as a brake on everyday hotlinking, not as a security measure.

On Apache, in an .htaccess file, the documentation offers a simple rule:

SetEnvIf Referer example\.com localreferer
<FilesMatch "\.(jpg|png|gif)$">
    Require env localreferer
</FilesMatch>

As written, this rule also rejects requests without a Referer; the mod_rewrite variant on the same page lets them through and can serve a replacement image. On Nginx, in the server block, the referer module does the sorting:

location ~* \.(jpe?g|png|gif|webp|avif)$ {
    valid_referers none blocked server_names *.example.com;
    if ($invalid_referer) { return 403; }
}

Behind a CDN, images served from its cache never reach your server: protection has to be turned on in the CDN itself, such as Cloudflare's Hotlink Protection.

For WordPress

Blocking blindly can make your images vanish from Google Images or from link previews on social networks, which bring you visitors. Start by observing. WP Feint Pro offers image hotlink detection for this: in Detect mode, it lists the sites displaying your images, with the number of requests and the estimated bandwidth, without blocking anything; in Protect mode, it returns a “Protected image” picture, a transparent pixel or a 403 error, while always letting through your own site, requests without a Referer, search engines and social networks. It writes its rules to .htaccess on Apache and LiteSpeed, and provides the block to copy on Nginx. Like any protection of this kind, it doesn't see images served by a CDN, or copies of images hosted elsewhere.

The effects on image SEO are covered in our article on masking and its real effects on SEO.

Further reading

  • Article Hiding WordPress and changing addresses: the real effects on SEO
  • Page Image hotlink protection

Sources

  1. Apache HTTP Server: When not to use mod_rewrite (image hotlinking) (external link, opens in a new tab)
  2. nginx: Module ngx_http_referer_module (external link, opens in a new tab)
  3. MDN: Referer (external link, opens in a new tab)

All definitions

Start free, go Pro when you’re ready

The free version already hides WordPress and moves the login page. Pro adds aliases, two-factor authentication and monitoring.