Prevent hotlinking with a .htaccess file


Hotlinking refers to linking directly to non-html objects on other servers, such as images, movie files etc. This can greatly impact bandwidth usage.

To simply stop hotlinking you can add the following to your .htaccess file. Replace example.com and the-other-example.com with your own domain name.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?the-other-example.com(/)?.*$      [NC]

RewriteRule .*\.(gif|jpg|jpeg|bmp|png|js|css|html|htm)$ - [F]
# To serve alternate content when hotlinking is detected. You can set up your .htaccess file to actually display different content when hotlinking is attempted.
# RewriteRule .*\.(gif|jpg|jpeg|bmp|png|js|css|html|htm)$ http://www.example.com/displeasure.gif [R,NC]

No comments:

Post a Comment