What is the best .htaccess code for preventing users from downloading web fonts

Posted on 2011-10-21
Last Modified: 2012-05-12
Over on StackOverFlow   there is a thread on preventing users from downloading webfonts or hot linking web fonts.  Some guy somewhere else said to use a .htaccess file with

Order allow,deny
Deny from all

which is of course duh... wrong because it will not deliver the font at all. Here is another so-called solution.

SetEnvIfNoCase Referer "^https?://([^/]*)?example\.com/" local_ref=1
SetEnvIf Referer ^$ local_ref=1

<FilesMatch "\.(eot|svg|ttf|woff)$">
  Order Allow,Deny
  Allow from env=local_ref

But this does not work for me either...if I use the above... the fonts are not sent by apache.
Question by:Sivakatirswami
    LVL 53

    Accepted Solution

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
    RewriteRule \.(otf|ttf|oet)$ - [NC,F,L]

    Open in new window

    In that final line add any other file extenions that you need to protect.  That will allow only requests from pages on your domain.  If you need to allow access for another domain. then repeat line 3 with the name of the domain you want to grant access to.  You can add as many domains as you need to.

    Author Comment

    Yay! it works. Thanks Cobol

    Fonts delivered here:

    but you can't get in here:


    Author Closing Comment

    [shameless EE advocacy} Lots of other places on the web for getting solutions, but, frankly, not always the what could be considered best practices, or accurate. EE's experts always deliver.
    LVL 53

    Expert Comment

    Yah, that works for just about anything.  Mostly it is used to keep leeches from hot linking to images instead of hosting them on there own server.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
    When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now