Prevent Image Hotlinking

Using Htaccess

by — Posted in Tutorials on April 26, 2015 - with views

Image Theft

Prevent hotlinking to your site's images, thus potentially saving a ton of bandwidth.

Prevent Other Sites from Embedding Your Images

Lately, I've had clients who have experienced image theft via hotlinking. Unfortunately, many ApacheConf code snippets don't work well. Below, you'll find the code you should use. However, keep in mind the following:

  • Place Code in an IfModule

    If you don't do this, and the module is not active, you're in for a world of hurt.

  • Joint Canonicalization

    The following snippet allows for both www and non-www domains in a single line.

  • REQUEST_FILENAME Utilization

    The snippet also used REQUEST_FILENAME to identify the requested filenames rather than the referring domain. I believe this is more optimal.

  • Checks if requested file exists

    Since we're serving an anti-hotlinking image, checking whether or not the file exists saves bandwidth if a requested file does not, in fact, exist.

  • Ignores Casing

    Utilizing of the [NC] flag ensures casing does not matter, meaning both uppercase and lowercase letters are treated as the same.

  • Allows Your Subdomains

    Via the ([^.]+\.)? regex, in line #6, your subdomains will not be blocked.

  • Search Engine Access

    Due to the fact that we want search engines to find our images, lines 7-9 allows for their access.

The Code

Thank you for reading.

I Would Love To Hear What You Have To Say

Comment using Facebook, Yahoo, AOL, or Hotmail below.

AngularJS Logo
jQuery Logo
FuelPHP Logo
Wordpress Logo
Bootstrap Logo
Github Logo

Web Design

I specialize in beautiful, clean, and usable web design. Perfect for businesses, organizations, and and online stores looking to maximize engagement.

Application Development

Have an idea a little larger than "a website?" Well, a webapp might be the perfect solution. I focus on standards-based, object-oriented programming.

eCommerce

eCommerce websites need to be comprehensive, intuitive to search and navigate, and mobile friendly. If it's time to make money selling, I'm your guy.

Consultation

Not sure exactly what you need? With my experience, I can serve as a valuable asset to your business or team in the form of consultatory services.

Marketing

Interested in developing out your brand further? Online marketing and advertising can yield high dividends in your brand awareness and saturation.

Strategy

Many wonderful ideas are large and need proper planning and execution. Together, we can determine set phases to deploy your business's online presence.

View More Services

Completely Free! Privacy guaranteed.