htaccess

Prevent Hotlink Images With htaccess

There is a way you can prevent people hotlinking the images on your website just by adding bits of code in your htaccess.

Images

Hotlinking

Hotlinking is when people use images from another site on their own site. This is a common practice which will waste a lot of bandwidth from the site that hosts the images.

With many hosting accounts you have a limit on the amount of bandwidth you can use and if you are wasting your bandwidth on other people using your images on there site you could reach your limit quickly. If these websites get lots of traffic then the bandwidth on your server will go up and your website isn't getting any of the visitors.

There are a few tricks you can do to prevent people from hotlinking your images but I am going to show you one way to prevent hotlinking of your images using htaccess.

Copy the following code snippet into your htaccess file to prevent hotlinking your images by redirecting all hotlinking to one image.

RewriteEngine On
#Replace ?yoursite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/dontstealmyimages.jpg with your NO hotlink image.
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/dontstealmyimages.jpg [L]

One trick to remember is to set the dontstealmyimages.jpg to be a massive file like 50000 x 50000 pixels. This will make the hotlinking page load really slow. The problem is that the bandwidth will come from your server so if your not limited to the amount of the bandwidth you use this is a nice trick.

Back to top ^

Join Paulund

  • Get access to 100s of premium tutorials and downloadable content
  • Members content consists of Premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • Priority email development support
  • No ads

Here at Paulund you'll find Web Development tutorials and snippets focusing mainly on PHP, WordPress and CSS. Members will get access to premium tutorials that go into more detail about development with these languages. You will also get access to downloadable premium content based on the tutorial.

Join Paulund

Leave a Reply

Your email address will not be published. Required fields are marked *