How to Prevent Hotlinking in Joomla

Hotlinking is one of the most annoying problems on the Internet that website owners have to deal with. Hotlinking is when one website includes in one or more of its pages a reference to one or more of your images (or videos, or pdf documents, or music files, etc…). In other words, let’s say that you have, on your Joomla website (let’s call your website yourjoomlawebsite.com), an image called robot.jpg under the images/stories directory. That image is about 1 MB in size. Another website (let’s call it leecherwebsite.com) has a page called leecherpage.html that has some text and the following HTML code:

<img src="http://yourjoomlawebsite.com/images/stories/robot.jpg" title="checkout this cute robot!" alt="checkout this cute robot!">

As you can see, the page leecherpage.html directly referenced your image on your website, which means that every time someone visits that page, that someone will consume from your bandwidth (because your website will serve the image). The problem gets worse when the image is retrieved from the database (and not stored on the file system) because of the overhead on your database engine and subsequently your processing power (which will eventually make your website slower). The problem gets far, far worse when a page is hotlinking to one of your self-hosted videos – this will literally drain your bandwidth.

In short, hotlinking (also referred to as leeching or inline linking) is theft of bandwidth, but there is currently no law (at least a law that we’re aware of) that prevents a website from hotlinking to another website. So what can you do to prevent hotlinking to your Joomla website?

Well, the only way to prevent hotlinking is by editing the .htaccess file, which can be found in the root directory of your website. So, you will need to add the following lines to your .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourjoomlawebsite.com/.*$ [NC]
RewriteRule \.(bmp|gif|jpg|png|svg|avi|mp3|wmv|css|js|pdf)$ - [F]

The above lines will block hotlinking to nearly all of your images, movies, MP3 files (music files), CSS files, JavaScript files, and PDF files. You can also prevent hotlinking to more file types, all you need to do is add the extension type of that file in the last line. For example, if you also want to prevent hotlinking to your xml files, then the last line in the above code will be:

RewriteRule \.(bmp|gif|jpg|png|svg|avi|mp3|wmv|css|js|pdf)$ - [F]

If you need help in preventing hotlinking to your Joomla website, then you can just contact us. We’re always a call or an email away, we’re very helpful, and we’re very friendly! Oh, and our rates are super cheap!

4 Responses to “How to Prevent Hotlinking in Joomla”
  1. Comment by Rembo — June 20, 2013 @ 1:44 am

    I’m guessing that last line should read:

    RewriteRule \.(bmp|gif|jpg|png|svg|avi|mp3|wmv|css|js|pdf|xml)$ – [F]

  2. Comment by Fadi — June 20, 2013 @ 6:16 am

    Hi Rembo,

    You’re absolutely right – sorry for the oversight.

  3. Comment by Diederik D'HErt — September 13, 2013 @ 3:14 am

    But will Joomla be able to access these files?

    I would like to have some PDFs in a directory, and be able to link (and open) the PDFs from an article in Joomla. Is that possible with this .htaccess addition ?

  4. Comment by Fadi — September 24, 2013 @ 2:31 pm

    Hi Diederik,

    Yes Joomla will be able to access these files – just upload anything through the Media Manager and Joomla will be able to access it (if given the right permissions of course).

Leave a comment