Guides

How to Prevent Image Hotlinking

Check whether external embedding is allowed and choose an appropriate protection for public or private files.

Confirm what is being embedded

Hotlinking means another page embeds a file using your URL. It can consume bandwidth, but embedding may be part of your distribution strategy. Test a real image from the same origin rather than assuming the entire website is exposed.

Understand Referer limits

A server can allow or reject requests according to the Referer header. Some legitimate clients omit it and non-browser clients can forge it. Referer filtering discourages casual embedding; it is not authentication or protection against downloading.

Choose a protection

Cloudflare Hotlink Protection is useful for the image extensions it supports. Review current coverage before assuming it also protects PDF files or videos. Apache and Nginx rules can target other extensions, but need to fit your existing routing.

Review an Apache example

The example allows an empty Referer and same-domain or subdomain referrers for example.com. Replace the domain carefully and verify the regular expression boundaries. This requires mod_rewrite. Test image delivery, search previews and legitimate integrations.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://([a-z0-9-]+\.)*example\.com(:[0-9]+)?(/|$) [NC]
RewriteRule \.(jpe?g|png|gif|webp|avif)$ - [F,NC]

Use signed access for private files

For private downloads or paid assets, authorize access on the server and use short-lived signed links or another access-control system. Avoid publishing secret tokens in static JavaScript. Hotlink rules alone do not protect premium files.

Retest without overclaiming

Run the checker after changes and test the asset in a normal browser. A block on one image does not prove every resource is protected. The checker provides a sample and should state unknown when it cannot reach a usable resource.

Recommended next step

Hotlink Protection Checker

Reference: Official documentation