How To Block Direct Image Linking Using .htaccess

 


Most of us have a certain amount of traffic that our web servers can manage for us. That limit seems to be quite generous — until you consider picture downloads and the bandwidth needed. It's one thing for a few dozen people to download a picture. But what if you have a picture that is popular on hundreds of other websites?

Worst-case scenario: you operate a website that obtains a photograph taken by an Iraqi soldier of an event that garners a lot of media attention. Assume you own the exclusive rights to that picture. You want to sell it, not give it away, therefore you don't make it available as a freebie. You may provide a downloadable version that others can use to publish on their own website, usually with a link back to yours. However, your original picture is solely for your own use.

Here's the issue. Webmasters, who are frequently inexperienced and unaware of why what they are doing is detrimental, strive to provide the best possible picture to their readers. Rather of downloading your free image or connecting to your site, they include a link in their own page that downloads just your photo as part of their own website. This is simple; just utilize the picture link to go directly to the other page.

With the great and profitable picture mentioned above, you might have blogs on both sides indexing you, as well as news or image sites indexing you. How much bandwidth can your site use before exceeding your monthly limit? Even a moderate-case situation is likely to convert your site into a DNS, and you will lose visitors and site ranking while you are inaccessible. Is it really worth sharing that amazing photo anymore?

However, there is another option: the.htaccess file. This is mainly applicable to Apache servers; if you're unsure, contact and inquire. Because not all systems will accept them, and some may be harmed by incorrect.htaccessing, you should consult your server administrator before uploading one.

What Is the Meaning of.htaccess?

For years,.htaccess files have been used to limit access to restricted web pages or regions, such as error pages and password-protected folders. You write it in a text editor like NotePad or SimpleText and save it as ordinary (ASCII) text. When you save it, change the file extension from.txt to.htaccess – and leave the rest of the name out. Your file should have no other name than.htaccess. It's not file.htaccess. It's just.htaccess.

If your text application insists on adding the.txt, you may delete it by right-clicking the file wherever you usually access it and selecting Rename. If your computer system does not display file extensions, learn how to make it do so! You may also rename files and remove extensions using telnet and ftp applications.

Making.htaccess Files

The first step in generating this file is to open a text editor and save an empty page as.htaccess. Turn off the word wrap feature. .htaccess files are meant to be single-line instructions, and a word wrap may totally deviate from this and render your file useless, either by breaking lines in the incorrect place or by inserting unnecessary characters when it's uploaded.

When uploading an.htaccess file, it should be encoded as ASCII rather than binary. CHMOD the file to 644 or (RW-R—R—) so that it may be used by the server but not by browsers; readable.htaccess files can undermine your security by enabling hackers to find out what you've protected and where the authentication files are. (You may also avoid this issue by placing your authentication files above the root directory, where they will not be accessible through www.)

An.htaccess file affects the directory it is placed in as well as any subsequent subdirectories; if you want to safeguard files everywhere, put the.htaccess file in your root directory. You may place it in your pictures directory if you just want to secure your photographs. Reading up the directory tree, the.htaccess file that is closest to any given directory is the one that is applied to that directory. Use as few.htaccess files as possible; redundancy may lead to an endless loop, which is undesirable for your site.

Keeping Hot Linking at Bay

The most essential thing you want to accomplish with an.htaccess file is to prevent non-HTML items like pictures and videos from being hot linked. Hot connecting is sometimes known as "bandwidth theft."

Your.htaccess file will prevent hotlinking; instead of the picture your thief is attempting to use, they will see something different, such as a broken image symbol or content you designate (angry men are popular).

The following should be in your.htaccess file:

HTTP REFERER on RewriteCond percent RewriteEngine!

$ RewriteCond%HTTP REFERER!

http://(www\.)?mydomain.com/.*

[NC] $
.(gif|jpg) RewriteRule
- [F] $

You don't need to change anything in the first two lines. However, the third line's http://mydomain.com must be replaced with your URL. The fourth line in the example is set up to prevent the usage of GIFs and JPEGs; you can add any other file type you like by using a pipe (|) separator.

If your server is configured to provide alternative content (ask your server administrator), you may add the following code to the fourth line of code in the.htaccess file to do this:

.(gif|jpg) RewriteRule

$ angryman.gif http://www.mydomain.com/angryman.gif [R,L]

This displays an angry-man picture you have in your directory; as previously said, make sure you update the domain name to the correct one.

Post a Comment

Previous Post Next Post

Sidebar Ads