How to Stop Image Hotlinking With cPanel Hotlink Protection
In this article9 sections
Someone copies a photo from your site and embeds it on their page. Every time their visitors load it, the image is served from your server, and you pay for the bandwidth. Your site slows down, your storage bill grows, and your own images appear on a page that does not credit you. This is called hotlinking. cPanel has a built-in tool to stop it, and it takes a few minutes to set up. This guide explains how hotlink protection works, how to turn it on, which sites to allow, and how to check that it blocks the right requests and nothing else.
Hotlink protection is available on Siteharbour’s cPanel hosting plans. It works on images, PDFs and other files that you serve from your own account, and it does not protect a file that is also on another host.
How hotlink protection works
When a browser loads an image, it sends a request with a referrer header that names the page it is on. Hotlink protection reads that header. If the referrer is your own domain, or a domain you have allowed, the image is served. If it is any other site, the server returns a blocked image or an error instead. A visitor who opens the image directly, with no referrer, is usually allowed, which is the normal case for a person looking at a file.
Because the check depends on the referrer header, some browsers and privacy tools remove it. Those visitors may see the protection’s fallback image even though they are on your site. Set the protection up with that in mind, and test it from the browser your visitors use.
Step 1: Open Hotlink Protection in cPanel
In cPanel, open Hotlink Protection under Security. The page shows whether the protection is on and a list of domains that are allowed to link to your files.
Step 2: List the domains that may use your files
Enter every domain that should be able to show your images. Include the domain itself, and the www address if the site uses it. Add any partner site or service that embeds your images on purpose, such as a newsletter provider or a page builder. Use the address without http:// and without a trailing slash, one per line, as the form asks.
Expected: the list shows each domain you added. A domain you forget will see the blocked image, so check your list against the sites that really use your files.
Step 3: Choose what to show instead
You can redirect blocked requests to a page of your choice, or show a specific image in place of the one that was blocked. A small image with your logo and a line about the source works well, because it tells the other site why its copy broke, and it sends visitors to you. Use a small file, so the blocked request costs little bandwidth. Choose a plain image that does not show a rude message, because a site owner may still show it on their page.
Step 4: Turn the protection on and test it
Select Enable, then open one of your images in a browser by its direct address. Expected: the image loads. Now test from a page that is not on an allowed domain. You can create a plain HTML file on a free test page, or use an online test tool that sends a referrer, and embed one of your images. Expected: the replacement image shows instead of your original.
Test a page of your own site too. Every image on your pages must still load, because a missing domain in the list breaks the images on your own pages.
Step 5: Check the log for blocked requests
The access log shows blocked requests with the referring site. Look at the log after a day to find who is linking to your files, and whether a legitimate partner is blocked by mistake. Read the log with a short command over SSH:
grep -i "example.org" ~/logs/example.com.access.log | tail -n 20
Replace example.org with the site you are checking. Expected: lines that show the requests that came from that site. If a partner’s visitors are blocked, add the partner to the allowed list.
Step 6: Keep the list current
Review the allowed domains once a year, and whenever you change a partner or a service. Remove domains that no longer use your files, so the list stays short and the protection stays strict.
Common mistakes
- Forgetting your own domain. Your own pages then show the replacement image.
- Adding a partner without testing. A typo in the domain blocks the partner’s visitors.
- Using a large replacement image. Every blocked request then costs more bandwidth.
- Expecting it to stop copying. It stops hotlinking only. Someone can still download and re-upload the file.
- Relying on it for private files. Use a password or a login for files that must stay private.
Frequently asked questions
Does hotlink protection stop people downloading my images?
No. It stops other sites from showing your files on their pages. A person can still save an image and upload it elsewhere.
Why does my image show on some browsers and not others?
Some browsers and privacy tools remove the referrer header, so the server cannot tell the request came from your site. Those visitors may see the replacement image.
Will this slow my site down?
It adds a small check to each image request, which is negligible. It usually saves bandwidth overall, because blocked requests are cheap.
Does it protect PDFs and other files?
Yes, for files on your account. Apply the same allowed list, and test a PDF link the same way as an image.
Hotlink protection is a cPanel setting that stops other sites from using your images, and it takes minutes to set up. List your own domain and any partner that really uses your files, choose a small replacement image, and test from a page that is not on the list. Check the access log after a day, and keep the list short. For the other access controls on the account, read how to keep your cPanel account and sites secure.