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.

  1. Login into your cPanel.
  2. Select HotLink protect cpanelNavigate to the security section and click the HotLink Protection icon.
  3. Enable hotlink protect cpanelTo 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.

    holtink protect enabled cpanelYou should see "HotLink Protection is currently enabled" on the "HotLink Protection" page.

    Hotlink protect codeIf you open your .htaccess file, you will see the code written to the file like the snapshot to the right.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Support Center:
Email Address
Optional, but our team may contact you for more information.
Like this Article?

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Write New!
Do you want to publish a tutorial to our support center?

News / Announcements

SSL Certficate Warnings
Updated 2014-04-14 11:34 am EST
Hits: 2220
Heartbleed 0-day OpenSSL security bug
Updated 2014-04-14 04:43 pm EST
Hits: 5642

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!