How to disable file hotlinking in Apache with .htaccess

Apache: How to disable file hotlinking in Apache with .htaccess

If you want to ensure that every image requested comes with a HTTP referrer of your own site's URL then this anti image hotlinking .htaccess rule will help you out:

  1. RewriteCond %{HTTP_REFERER} !^$
  2. RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YOURSITE.com [NC]
  3. RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

Don't forget that you will probably need to enable the rewrite engine for these rules to work. Click the button below to find out how to do this.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to disable file hotlinking in Apache with .htaccess

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Apache language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to prevent Eloquent from adding created_at or updated_at timestamps?

How to fix the MySQL related "Specified key was too long error" error in Laravel

How to run an artisan command from a controller

What is an example of an object literal?

How to force gzip compression in Apache with .htaccess

How to check if a relation was loaded on an Eloquent model already?

How to check if a user is logged in, inside a blade file?

How to pick what array_intersect function to use in PHP?

How to block an IP range based on CIDR in Apache with .htaccess

How to set infinite execution time in a PHP script