Have a Question?

If you have any question you can ask below or enter what you are looking for!

Preventing Hotlinking

Hotlinking refers to the act of directly linking to files on your websites, such as images, videos, and archives, among others.

You might want to prohibit these ‘parasite’ requests to your files as it causes high bandwidth usage. You can prevent hotlinking using simple .htaccess directives.

If you already have an .htaccess file, all you need to do is add one of the following code snippets in the beginning of your existing file. If you don’t have an .htaccess file, you need to create a plain text file (e.g., htaccess.txt), upload it via FTP and then rename it to .htaccess on the server.

How to Stop Hotlinking

In order to stop hotlinking altogether, simply add the following to your .htaccess file. Make sure to replace “jolt.co.uk” on line 3 with your actual domain name.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)jolt.co.uk/.*$ [NC]
RewriteRule .(gif|jpg|zip|rar|mp3|flv|swf|png|pdf)$ - [F]

How to Return Alternate Content

Alternately, you can serve alternate content when hotlinking is detected by setting up your .htaccess file to display different content on attempts at hotlinking.

This is primarily done to display your displeasure of hotlinking activities. In the following example, we’re going to return an image of the devil instead of all hotlinked images. Make sure to replace “jolt.co.uk” on line 3 with your actual domain name. Also, upload devil.jpg to the website’s root directory.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)jolt.co.uk/.*$ [NC]
RewriteRule .(gif|jpg)$ http://www.jolt.co.uk/devil.jpg [R,L]

Make sure to only use these techniques if you’re certain that you don’t want your images displayed or other files used on all 3rd party resources.

Leave a Reply

You must be logged in to post a comment.