Practical WordPress Development

Update htaccess To Prevent Hotlinking

One of the sites that I manage was sucking an inordinate amount of bandwidth over the past week or so.

The raw access logs showed that an image that I was hosting was being referenced on a number of different sites. Preventing this from happening is an easy fix:

Locate your .htaccess file and add the following lines:

# Begin Disable Hotlinking of Images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(feeds.)?*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
RewriteRule .(gif|jpg|js|css|png)$ - [F]
# End Disable Hotlinking

Don’t forget to replace “” with your domain name.

This particular update will prevent anyone from hot linking images from your site. If you want to do the same for additional files (such as JavaScript, CSS, etc) you can add the file types:

RewriteRule .(gif|jpg|png|css|js)$ - [F]

Easy enough.


  1. Kyle Reed

    I need a little more help, where would I find this? I am pretty positive its not in my theme but in wordpress on my FTP correct?

    • tom

      This file’s in the root of where your site is hosted. For example, if your site is hosted out of /public_html then .htaccess is located there.

      • Kyle Reed

        Got it. I had some issues with my feed the other day as well and went on a search. It is amazing what searching for solutions teaches you.
        I love it

Leave a Reply

© 2020 Tom McFarlin

Theme by Anders NorenUp ↑