Protecting Images

There are many things you can do to help keep your cost of hosting down. One area is to keep your bandwidth usage to a minimum. Unfortunately, other webmasters do this too by "hotlinking" to other webmaster's images. What this means is they use your photos and your bandwidth (by copying your image location and inserting it into their code), to provide content for their website. You get charged for the bandwidth while they get to use your content. Very unethical and a problem which will continue as long as bandwidth costs money (which will always be the case).

We have recently setup our Apache webservers to enable the mod_rewrite feature. For most of you this technical jargin means nothing. So lets just get on to the meat and potatoes of this and how it will help you.

How it works
For many of you who use password protection for your website in some form or fashion, you will be familiar with the .htaccess file to some extent. This is used to force the server to ask for a user name and password. If there is a match in the password file then the user is allowed access. If not, they are returned a page indicating their Authentication failed. Protecting your images will be similar in a way. By placing the proper .htaccess file into a directory containing pictures, each time an image is accessed, the server determines if it is being called from an acceptable location. These parameters are located within the .htaccess file. If it is, then the image is displayed. If not, they are redirected to an html page of your choice, or if the image is a source tag, the typical icon for an image not found is displayed.

An example
This is how it works when your site is setup with the mod_rewrite feature. Here is a breakdown of the structure of the site:

  • http://www.sirrushosting.net (the root of the site) entrance
  • http://www.sirrushosting.net/images/ contains all the photos and pages
  • .htaccess file is located within the images directory
  • So what happens here. If you go to warning page and enter the site by normal means, you gain entry. If you try to go directly into the images directory of the site, you get redirected back to the warning page. Because the images directory does not allow access from any location within itself with the exception of any variation of sirrushosting.net, access is denied and the surfer is redirected to the warning page (where they will be able to enter the site properly and view all the contents of the site). Any domain or site linking into the personal directory will direct any surfer going through the link directly to the warning page.

    1. The site is protected from hotlinking. Purpose achieved...
    2. In addition to protecting the images, the webmaster has also achieved another goal of forcing all surfers coming into the site to take a designated path through the site. This is beneficial force the surfer to view whatever advertising banners or information the webmaster wants the surfer to see.

    Installation
    Installation is rather easy if you have some knowledge of unix commands. Make edits to the necessary areas of the file (self explanatory) in the window and then proceed to the steps below.

    1. In the window above, you will change each "RewriteCond" line to show what domain you are allowing access from. You can place as many domains or ip addresses here as you would like to allow access. Please note that if you have users accessing your page by yourdomain.com as well as www.yourdomain.com, these will both need to be entered above.
    2. Create a file called .htaccess. Cut and paste the information above into the .htaccess file. You can either use FTP to upload the file or use telnet to create the file from scratch. Test the installation out and you are set.

    IMPORTANT: This feature of the apache webserver is NOT supported by our technicians. If you have questions about installing it or would rather have us install it for you (there is a charge for the labor), please contact tech@sirrushosting.net.

    Hosting Resources Advertising Site Info Turtorials Contact Start New Account Online Payment