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 and with your own domain name.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$      [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)$ [R,NC]

No comments:

Post a Comment