Preventing Bandwidth Stealing on Apache Servers The other day I wrote about how some people are not only stealing our
pictures, but also our server bandwidth. Today I will tell you of a solution I
have implemented on Kamat.com. Many people write scripts (in languages such as
Perl, PHP or ASP) to prevent unauthorized linking to websites. However, Kamat.com is
not a dynamic website, but a statically rendered website designed for
high-performance, so I did not have that luxury (see Amateur Webmaster: Static Rendering of Websites). However, Apache server has a
very powerful feature called Rewrite Rules by which the server behavior can be
changed dynamically with the help of rules. The end result is same as that
implemented by scripts performing the same functions, but with this approach I
did not have to change any of our content production or publication system.
Without further ado, I present the solution:
RewriteEngine onRewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://kamat.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://kamat.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.kamat.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.kamat.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://216.122.12.236/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://216.122.207.82/.*$ [NC] RewriteRule .*\.(gif|GIF|jpg|JPG)$
http://www.kamat.org/illegal.gif [R]
Commentary
In line 1, tell the server to alter (or rewrite) its rule for serving. In
lines 2 through 8 I define all the authorized server linking. This is necessary
because people might be entering the website via different naming conventions
(upper case, lower case, IP, with and without the www sub-domain). In line 9, I
redirect the unauthorized request to a Copyright
Violation Notice. Just put the above rules in your WebServer configuration file, and you are
done. I couldn't believe how simple it was. Do not try to do a similar
thing with Microsoft Internet Information Server (IIS), because you simply can't
-- a solution with IIS requires that your website is dynamically served. The Amateur Webmaster: Tips for amateur (and professional) webmasters.
(Comments Disabled for Now. Sorry!) | First Written: Saturday, November 17, 2001 Last Modified: 11/16/2001 |
|