Skip to main content

How to Block Hotlinking and Protect Your Resources

Updated over 2 weeks ago

Hotlinking occurs when other websites directly link to the media files (images, videos, audio, etc.) hosted on your server. This can cause several issues, from excessive bandwidth usage to security risks and SEO problems.

If you use WordPress, it’s important to protect your content to prevent third parties from using it without permission. Below, we explore the main consequences of hotlinking and how to prevent it.

Problems Caused by Hotlinking

🔵 1. Excessive Bandwidth Consumption


📌 Impact: Other websites can link to your images, videos, or other files, consuming your server resources. This can generate additional costs or affect your site’s performance.

⚠️ Consequence: If your hosting has a bandwidth limit, your site may become inaccessible to legitimate visitors. (Note: Some providers, such as Sered, offer unlimited bandwidth, but it’s still recommended to protect yourself from hotlinking).


🔵 2. Risk of Content Exploitation

📌 Impact: If private or misconfigured files are accessible, attackers can link to them directly and use them without your permission.

⚠️ Consequence: Exposure of private data or content that should not be public.


🔵 3. Damage to Reputation and Brand


📌 Impact: Malicious sites may use your content without authorization, associating it with fraudulent or illegal activities.

⚠️ Consequence: It can harm user trust in your website or business.


🔵 4. Vulnerability to DDoS Attacks


📌 Impact: An attacker can link your files on high-traffic websites or use scripts to overload your server.

⚠️ Consequence: Resource saturation and site downtime.


🔵 5. SEO Problems


📌 Impact: Search engines may index your images on other websites, reducing traffic to your own site.

⚠️ Consequence: Loss of ranking and authority in search engines.


How to Configure It?

Open your site’s .htaccess file and add the following code. This code essentially specifies which websites are allowed to access the formats uploaded to your site (images, videos, documents, music, etc.).

You only need to replace the domain name in this code with your own. This way, uploaded resources will only load from your domain:

<IfModule mod_rewrite.c>
RewriteEngine On

# Allow access from your domain and subdomains
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)midominio\.com(/.*)?$ [NC]

# Block access to specified resources
RewriteRule \.(jpg|jpeg|png|gif|bmp|svg|webp|mp4|mp3|pdf)$ - [F,NC,L]

</IfModule>

For example, for the site"guiasered.net", it would look like this:

<IfModule mod_rewrite.c>
RewriteEngine On

# Allow access from your domain and subdomains
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)guiasered\.net(/.*)?$ [NC]

# Block access to specified resources
RewriteRule \.(jpg|jpeg|png|gif|bmp|svg|webp|mp4|mp3|pdf)$ - [F,NC,L]

</IfModule>

If you want to allow subdomains, add the following rule below the RewriteCond lines:

RewriteCond %{HTTP_REFERER} !^https?://(www\.)?subdomain\.your-domain\.com(/.*)?$ [NC]

If someone tries to use an image from your website by linking directly to it, they will get an error, and the image won’t load on unauthorized external sites.

This way, hotlinking will be blocked.


Conclusion

Hotlinking can affect your site’s performance, compromise security, and damage your reputation. Implementing a block in .htaccess is an effective way to prevent others from using your files without permission.

If you manage a WordPress site, you can also use security plugins like All In One WP Security or Wordfence, which include options to protect your content.

🔹 Recommendation:
Always check access logs and monitor your website traffic to detect potential abuse. Keeping good control over your files and settings is key to protecting your online project. 🚀


Did this answer your question?