Hot-linking files such as images and media (mp3, wma etc..) is where another website uses source code to post your media on thier page. This uses your bandwidth and the other site gets credit for this.
This snippet of code will prevent anyone but your domain to view or access your media. If others are hosting images that are yours they will simply have the big red x.
There are 4 variants of this code, experiement with them to find the one that works for you.
To implement this you will need to create a .htaccess file in the stored directory. If your images are in /web/images then you will need to post this .htaccess file in the images directory to prevent hotlinking there.
Note, only enter the tld of your domain. Such as yourdomain.com instead of
www.yourdomain.com..
Application is:
cd /web/images
vi .htaccess
Paste your desired variant (some may not work with your hosting setup, try until one does).
Variant 1
Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]
|
Variant 2
Quote:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]
|
Variant 3
Quote:
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]
|
Variant 4
Quote:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]
|
If your using an Ensim based server 3.1 or 3.5, 3.7 then you'll need to add
ReWriteEngine On to the 1st line of code.
If you need to block additional file types just add thier extensions to the Rewrite Rule Line.
Removal:
Simply delete the .htaccess file in your directory.
1. rm .htaccess
Regards,
Ryan