What is HotLinking? HotLinking is when you use a url to view an image in the website code or the image url in the browser. When using url's in image code, the server does not have to use any bandwidth or http request to serve the image. Say I use a url to an image at Yahoo in my code. Yahoo's server will need to serve the image and not the server my site is on. For example, you can get the url to an image for a site like the following from yahoo:
http://l1.yimg.com/dh/ap/fp/rsz/012413/home_uni_1359057924.jpg
This can be used in your code to display the image on your website. The code looks like the following.
<img src="http://l1.yimg.com/dh/ap/fp/rsz/012413/home_uni_1359057924.jpg" />
Why HotLink Protect your website? When people HotLink to your website, they are actually using your server resources instead of their own. When your images are HotLinked by many different people on their sites, your site can start to slow down and go under a load. Another reason is to prevent people from using your images on their site as if the image is their own. You can prevent the images from being used with HotLink protection. Lets learn how to HotLink protect through the .htaccess and through the cPanel HotLink protection feature.
Hotlink protection .htaccess code
Code can be added directly to the .htaccess to prevent HotLinking in a directory specific location. The following code is used to prevent HotLinking to jpg, jpeg, gif, png, and bmp file types.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-website.com/.*$ [NC]
RewriteRule \.(jpg|jpeg|gif|png|bmp)$ - [F]
Redirecting hotlinked visitors to a specific page
You can redirect people to a specific page if they try directly accessing your images through the url of their browser.
http://www.my-website.com/restricted.html
This applies to visiting the image url in the browser, The following code will show how to redirect anyone going to a jpg, jpeg, gif, png, and bmp file to a "restricted.html" page.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-website.com/.*$ [NC]
RewriteRule \.(jpg|jpeg|gif|png|bmp)$ http://www.my-website.com/restricted.html [R,L]
Using the HotLink Protection in the cPanel
A feature that is included in cPanel is the HotLink Protection feature. The HotLink Protection in cPanel writes the .htaccess code for you. Below are the steps for using the HotLink Protection in cPanel.
- Login into your cPanel.
Navigate to the security section and click the HotLink Protection icon.
To allow url's in the browser to access your images, select the "Allow direct requests" checkbox. This will let the visitor to navigate to the url in the browser while denying image linking through the code of a site.
You should see "HotLink Protection is currently enabled" on the "HotLink Protection" page.
If you open your .htaccess file, you will see the code written to the file like the snapshot to the right.
0 comments:
Post a Comment