in 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 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.

Subscribe To The Weekly Newsletter

Get weekly updates to your email