Hotlink protection: How-To prevent people from stealing your files


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Apache Related Information

Hotlink protection: How-To prevent people from stealing your filesLast Modified: Dec 5, 2019, 4:12 pm
Create an .htaccess file in your public_html directory with the following code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domain.com.*$ [NC]
RewriteRule .(gif|jpg)$ - [F]

Where domain.com is your domain.

Similarly, you can set this up to allow only a list of multiple domains:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domain1.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?domain2.com.*$ [NC]
RewriteRule .(gif|jpg)$ - [F]

Where the logic reads
  • If the referer is not blank
  • and is not domain1.com
  • and is not domain2.com
  • and is accessing a gif or jpg
  • Then [F]orbid the request.
  • Where you can add more domains in a similar manner, as needed.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST