-->
  • Latest Comments

    • Guinevere: I love you. :heart:
    • Carol Orvis: Hi Allen! I used to watch Sesame St. with both Shelby and Guin when they were young. They would sit in...
    • Allen: testing comments! :BOMB:
    • Big Al: Sesame ruled. I remember those clips. Talk about retro. :D
    • Brian: yeah, weird, trippy, and great! I remember seeing all of those, so great. always liked the guy who turned into...
  • Upcoming Events

    • Popular on DIGG

    • Latest del.icio.us

    • Weather

    • Meta

    Bandwidth usage can escalate to extremes if a few people get their hands on graphics, videos and sound files that can be directly linked from your server/website. For example - somebody really likes an image on your website and instead of asking for permission, downloading the image and linking to it on their own site, they just copy the URL that leads to the image on your website and stick the code directly into their website. This way, they use your bandwidth for free, and you get to be hounded by your isp and charged extra when your image becomes popular with a large group of people, such as a community of copycats on myspace who don’t know any better.

    The solution is surprisingly easy. The addition of a .htaccess file in the top level of your site, or the addition of a few lines in your current .htaccess file will fix things up for you.

    The following is what I have in the .htaccess file to protect the site from having others directly link to content that I don’t want them directly linking to:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
    RewriteRule \.(gif|jpg|jpeg|mpg|mpeg|png)$ - [F]

    I’m not sure what the procedure is for every system, but the above will work for Apache servers. NOTE: you can put any file type in the Rewrite rule line. Just separate each file extension with a |

    Bandwidth After .htaccess changes

    The above graph is for the first few days of September, 2006. The 1st, 2nd and 3rd of the month show the bandwidth usage before the addition of changes to the .htaccess file. The 4th, 5th, 6th and 7th are after the changes. The previous month showed monthly bandwidth usage at over 40 gigabytes - for a personal website site is basically a blog.

    I used this article at selfseo.com for my solution.
    For more information on .htaccess files and what you can do with them, check out the Wikipedia entry on .htaccess.

    3 Responses to “Stop Direct Linking to Image Files on Your Server”

    I couldn’t find that file on my site; looked in / and /httpdocs. Maybe I need to go one higher or something.

    Msg me when you’re online and we’ll get this fixed up.

    Hey Chris…
    The file is there. It is just invisible. In linux filesystems, a . before the filename makes it invisible. I assure you the file is there and I have updated it to deny direct linking to the following file extensions:
    gif|jpg|jpeg|png|mov|avi|mpg|mpeg|wmv|mp4|asx

    If you want me to remove or add any just let me know.

    Here’s a similar solution that stops people from embedding your image/video files, but if they link to the file it gets embedded in a page of your design.
    http://alistapart.com/articles/hotlinking/

    The page also suggests allowing google to link to the images if you want them to show up in the cache and/or google images.

    Rob

    Something to say?