Hotlink protection in WordPress is usually requested as a plugin, installed as a plugin, and then judged by a bandwidth bill that does not move. The request never reaches WordPress, so no PHP code can answer it. Another site embeds your image, its visitors load the file from your server, and the traffic is billed to you.
We audit WordPress sites for clients, and this problem is one of the cheapest to fix and one of the most persistent. The fix lives at the perimeter: a Cloudflare toggle, valid_referers in nginx, or one rewrite condition in Apache and LiteSpeed. Below is why the application layer loses, what each rule costs you, and where our own plugin still has work to do.
What hotlink protection actually stops
A hotlink is an <img> tag on someone else’s page that points at your file. The browser of their reader connects to your server, not to theirs. Your disk serves the bytes, your traffic counter grows, and your page views do not.
Most of the time it is harmless: a forum post, a wiki, a newsletter. Sometimes it is a competitor filling a gallery with your photos. The damage is measured in gigabytes, not in stolen accounts, which is exactly why it belongs to a bandwidth policy and not to a security incident.
The request you are protecting never reaches PHP
A WordPress request that renders a page passes through PHP-FPM, wp-load.php, hundreds of plugin files and a handful of database queries. That is expensive. A request for /wp-content/uploads/2026/11/photo.jpg passes through none of it.
On a normal nginx or Apache setup, a static file is served by the web server directly. PHP is not started, WordPress is not loaded, and your hotlink plugin is not executed. The file leaves the machine at full speed before any PHP line runs.
That single fact decides the architecture. Protection placed after the engine cannot protect requests that skip the engine.
Even when a plugin does intercept something, the order of work is wrong. WordPress boots, loads every active plugin, opens a database connection, resolves the current user, and only then asks whether the referer is allowed. You paid for the full stack to say no.
Three rules that do the job
Rule 1: Cloudflare Hotlink Protection, one toggle
If the domain is proxied through Cloudflare, Scrape Shield has a Hotlink Protection switch. Turn it on, and requests with a foreign referer are refused at the edge, before they reach your origin. No configuration file, no server access, no PHP.
The limit is the word “proxied”. Traffic that bypasses Cloudflare, including direct-to-origin requests and some subdomains, is not covered. Cloudflare also allows empty referers by default, which is the right behaviour and the reason direct visits keep working.
Rule 2: nginx valid_referers
On your own server, nginx answers this in four lines:
location ~* .(jpe?g|png|gif|webp|svg|mp4|pdf)$ {
valid_referers none blocked server_names *.example.com;
if ($invalid_referer) {
return 403;
}
}
none keeps direct visits and clients that strip the header, blocked keeps referers that were mangled by a proxy, server_names accepts your own hostnames, and the wildcard covers subdomains. Everything else gets 403 and costs you a header, not a megabyte.
Rule 3: Apache and LiteSpeed
Where .htaccess is in play, the same policy is one condition and one rule:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www.)?example.com/ [NC]
RewriteRule .(jpe?g|png|gif|webp|svg|mp4|pdf)$ - [F,NC]
LiteSpeed reads the same syntax, so shared hosting gets the rule without a ticket. Both lines belong in the server configuration, not in a plugin that rewrites .htaccess behind your back and forgets to clean up when it is deleted.
What these rules break
Every referer rule breaks something, and the failures look like complaints rather than errors:
- a privacy browser or a proxy strips the header, and the visitor sees a broken image;
- an email client shows the picture by URL, with no referer at all;
- a social network fetches the preview image from its own infrastructure;
- a staging copy on
staging.example.comis blocked by a rule written forexample.com; - Google Images and Bing previews stop resolving.
This is why none and blocked are in the nginx line. A rule that denies empty referers blocks more legitimate traffic than hotlinks. Test before you ship: curl -I -e "https://other.example/" https://example.com/photo.jpg must return 403, and the same request with your own referer must return 200.
Hotlink protection is not access control
The Referer header is sent by the client. A scraper sets it to your own domain in one line of code and walks through the rule. So the honest framing is this: hotlink protection is a bandwidth policy for careless embedding, not a defence against a determined one.
The second job, deciding whether a request is a scraper, a fake crawler or a broken integration, belongs to the application layer. That is the part a WordPress plugin can do, because the plugin only needs to answer for requests that actually reach WordPress.
Where BotBlocker fits
BotBlocker does not replace the perimeter and does not pretend to: the network edge stays with the host or the CDN, while the application perimeter is ours. Our firewall runs before WordPress is fully loaded, checks request headers and User-Agent signatures, and writes the decision to a log you can read.
That covers the case hotlink protection cannot: a client that sends a forged referer, a scraper that rotates addresses, a crawler that claims to be Googlebot without a matching PTR record. Read how BotBlocker filters fake and dangerous referer traffic for the mechanics, and the feature list for the rest of the platform. Plans and limits are on the pricing page.
The split is simple. Perimeter rules cut the volume. The plugin decides who is on the other end.
Checklist before you switch it on
- Count the damage first: top referers in the access log and the bytes they pulled.
- Write down your own hostnames, including staging and the CDN hostname.
- Add the rule at the edge if you have one, at the server if you do not.
- Test four cases: own referer, foreign referer, empty referer, direct request.
- Watch the
403share for a week. A jump means a legitimate client was caught.
Turning the rule on takes minutes. Leaving it correct takes a look at the log once a month.
Background: Cloudflare Hotlink Protection, the nginx referer module, and Apache mod_rewrite.
