Protection from hotlinking

Last change on 2021-05-20 • Created on 2020-01-20 • ID: KO-EA1E9

You can use the following .htaccess file to ensure that your home page files are really only being retrieved by visitors to your site, and are not being abused by third party sites:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.tld(/.*)?$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|zip|mpg|GIF|JPG|JPEG|PNG|ZIP|MPG)$ - [F]

Replace domain.tld with your domain name. Add additional file endings if needed.

This is particulary useful for protecting pictures, videos, or other larger files. You should not use this method to protect HTML or PHP files; otherwise, it will no longer be possible to link your site.