Skip to content
Hotlink Protection

How to Stop Image Hotlinking

When another site embeds your photo straight from your server, you pay for every view and get nothing back. Here is how hotlinking works and how to block it on Apache, nginx, Cloudflare and WordPress.

Watermark.ws 6 min read Updated
A wallpaper website showing a Lofoten beach photo, loaded straight from the photographer’s server, with a Download button beside it The same wallpaper page once hotlinking is blocked, with an empty placeholder where the photo was
On this page

What Image Hotlinking Is

Image hotlinking is when another website shows your image by pointing at the file on your server, instead of uploading its own copy. Their page contains a tag like <img src="https://yoursite.com/photo.jpg">, so every time someone opens their page, the visitor’s browser downloads the photo from you.

A diagram: a visitor’s browser requests a page from wallpaper-hub.example, then requests the image from iriscalloway.com, sending Referer: wallpaper-hub.example. Below, the img tag that points at the photographer’s file
The page comes from their server. The photo comes from yours.

To stop image hotlinking, your server has to tell those two kinds of requests apart. It can, because when a browser loads an image for a page, it usually sends a Referer header naming the site the page came from. Hotlink protection reads that header and refuses image requests from sites that are not yours.

The short answer
  • Apache or LiteSpeed: a few lines of mod_rewrite in your .htaccess file.
  • nginx: the valid_referers directive in your image location block.
  • Cloudflare: switch on Hotlink Protection in the Security settings.
  • WordPress: your host’s hotlink setting, a security plugin, or one of the above.
  • Always allow requests with no Referer, and decide whether Google Images and Pinterest should still be able to show your images.

Why Hotlinking Costs You

  • Bandwidth. Every view on their page is a download from your server. One popular forum thread or wallpaper page can serve your full-size file thousands of times, on your hosting bill or your plan’s limits.
  • No visit, no credit. Their visitors see your photo without ever seeing your site, your name or your prices.
  • No say in the context. Your work can end up on pages you would never choose, next to ads that earn money for someone else.
A wallpaper website page showing the Lofoten beach photo with a Download button beside it Before protection
The same wallpaper page with an empty broken-image placeholder where the photo used to be After protection

There is one upside. Because a hotlinked image is still served from your server, you stay in control of it. Once protection is on, the photo disappears from their page, or is replaced by whatever you choose to send instead. A copy someone downloaded and re-uploaded is a different problem, covered at the end.

Protect the Copies, Not Just the File Add your name or website to every photo you publish, so saved and re-uploaded copies still point back to you. Start watermarking

Before You Block: What Hotlink Protection Breaks

Hotlink protection is a blunt tool. It blocks every other site, including the ones you want showing your images:

  • Search and social. Cloudflare’s own documentation warns that its Hotlink Protection has no effect on crawling but prevents images from being displayed on sites such as Google Images, Pinterest and Facebook. For a photographer, those can be valuable traffic, as do watermarks hurt SEO? explains.
  • Your other domains. A shop on a subdomain, a staging site or a separate blog that uses images from your main domain needs to be on the allowed list.
  • Feeds and newsletters. RSS readers and email services may load images from other domains.
A diagram of three image requests: Referer iriscalloway.com is sent the photo, a request with no Referer header is sent the photo, and Referer wallpaper-hub.example is blocked with 403 Forbidden or a replacement image
A good rule allows your own pages and requests with no Referer, and blocks the rest.

Two more things to know. Requests with no Referer at all, such as someone typing the image address, some apps and some privacy settings, should be allowed, or you will block real people. And the header is easy to fake, so hotlink protection stops casual embedding, not someone determined to get the file. The nginx documentation says as much: the aim is to block the mass flow of requests from regular browsers, not every possible request.

Stop Hotlinking With .htaccess (Apache)

On Apache or LiteSpeed hosting, add these lines to the .htaccess file in your site’s root folder, with your own domain in place of the example:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?iriscalloway\.com [NC]
RewriteRule \.(jpe?g|png|gif|webp)$ - [F,NC]

  • Line 2 lets through requests with no Referer, the pattern the Apache documentation uses so that people who type the address directly are not blocked.
  • Line 3 lets through your own site, with or without www.
  • Line 4 answers every other image request with 403 Forbidden.

To keep Google Images and Pinterest working, add a condition for each before the last line, such as RewriteCond %{HTTP_REFERER} !google\. [NC] and RewriteCond %{HTTP_REFERER} !pinterest\. [NC].

Sending a replacement image instead

Apache’s documentation also shows how to redirect hotlinkers to a different image instead of a 403. If you do, put the replacement in a folder or format the rule does not cover. Otherwise the request for the replacement is blocked by the same rule.

Test it afterward: open one of your pages and check the images load, then try embedding an image on a test page on another domain, or use a tool that lets you set a custom Referer.

Stop Hotlinking on nginx

nginx has a built-in module for this. Inside your server block, add a location for image files:

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

  • none allows requests with no Referer, and blocked allows ones where a firewall or proxy has stripped it.
  • server_names allows your own server names, and the *. entry covers subdomains.
  • The ~ entries are patterns; drop the Google and Pinterest ones if you want those blocked too.

Check the configuration with nginx -t and reload nginx. If your site already has a location block for images, for caching headers for example, add the lines there rather than creating a second one.

Cloudflare Hotlink Protection

If your site runs through Cloudflare, you can block hotlinking without touching the server:

  1. Open Security settings

    In the Cloudflare dashboard, select your site and go to the Security Settings page.

  2. Find Hotlink Protection

    Optionally filter by Client-side abuse to find it faster.

  3. Switch it on

    Toggle Hotlink Protection to On. It applies to the whole zone.

Cloudflare’s documentation describes exactly what it does: it denies image requests when the Referer does not include your domain and is not blank. It covers files ending in gif, ico, jpg, jpeg and png, so if you serve WebP or AVIF, check whether those need a separate rule.

There is no allowed list of other sites in the simple toggle. To let specific images be embedded elsewhere, put them in a folder named hotlink-ok, anywhere on your site, or create a configuration rule that turns protection off for a path or hostname.

Stopping Hotlinking in WordPress

WordPress itself has no hotlink setting, but you have several options, depending on your hosting:

  • Your host’s control panel. cPanel has a Hotlink Protection page where you list the URLs allowed to use your files, choose the file extensions, decide whether to allow direct requests, and can redirect blocked requests to another URL.
  • A security plugin. Plugins such as All-In-One Security (AIOS) include a prevent-hotlinking option that writes the rewrite rule into .htaccess for you. That only works on Apache or LiteSpeed servers.
  • Cloudflare. If your WordPress site sits behind Cloudflare, its toggle works the same as on any other site.
  • Managed hosts. Many run nginx, where .htaccess rules do nothing. Check your host’s dashboard or ask support whether they offer hotlink protection.

Whichever you choose, test with an image in a post and an image from the Media Library, and check a page that shares your post to social media still shows its preview image if that matters to you.

What Hotlink Protection Can’t Do

Hotlink protection only stops other sites from embedding the file on your server. Anyone who can see your image can still save it and upload their own copy, and from then on your server is out of the loop. That kind of copying is far more common than hotlinking.

A wooden boardwalk through dune grass leading to the sea, with © IRISCALLOWAY.COM in small white letters in the bottom-right corner
A watermark is part of the pixels, so it stays on downloaded and re-uploaded copies.
  • Watermark what you publish. A small name or website address on the image travels with every copy. See watermarking your portfolio website.
  • Publish smaller files. A 2,000-pixel image is plenty for a web page and much less useful for printing. Resizing photos before sharing covers sizes.
  • Look for copies. A reverse image search finds re-uploaded copies that hotlink protection never sees.
  • Skip the right-click blockers. They hide one menu and annoy visitors, as does disabling right-click protect images? explains.

If you find your photos on someone else’s site, hotlinked or copied, what to do when someone steals your photos walks through the options. Watermark.ws adds a text or logo watermark to a whole folder of photos at once, so everything you publish carries your name.

Sample photos: Lofoten beach by Dominik Schröder, Boardwalk to the sea by Aleksandra Boguslawska on Unsplash.

Protect the Copies, Not Just the File

Add your name or website to every photo you publish, so saved and re-uploaded copies still point back to you.

Start watermarking
  • No account needed to start
  • Works in your browser

Questions people ask

What does hotlinking mean?
Hotlinking means another website displays your image, video or file by linking directly to it on your server instead of hosting its own copy. Their visitors see your image, and your server pays for the download.
Is hotlinking illegal?
It depends on the country and the case, and courts have not treated it the same way everywhere. Whatever the legal position, you can block it technically on your own server, and if the site also copies your work, the usual copyright remedies apply.
Does hotlink protection hurt SEO?
It does not stop search engines from crawling your images, but a strict rule can stop Google Images, Pinterest and Facebook from displaying them. Allow those referrers if image search and social sharing bring you traffic.
How do I check if my images are being hotlinked?
Look at your server or CDN analytics for image requests with other sites as the Referer, or search for your image file names and run reverse image searches. Unusual bandwidth spikes with no matching rise in page views are another clue.
Does Cloudflare Hotlink Protection work with WebP images?
Cloudflare’s documentation lists the supported extensions as gif, ico, jpg, jpeg and png. If you serve WebP or AVIF files, check the current docs or add your own rule for those formats.
Will hotlink protection stop people from stealing my photos?
No. It stops other sites embedding the file from your server, but anyone can still save the image and upload their own copy. A visible watermark and smaller published files are what protect the image itself.