Preventing access to fonts with .htaccess Preventing access to fonts with .htaccess apache apache

Preventing access to fonts with .htaccess


This is completely impossible.

Instead, consider using an image, or removing unused characters from the font.


If you let something to get to the browser then its public. AFAIK there is no way to block the stuff that you let browser read it!

Edit this bit of code and you can make image of text with font you want (it need GD library):

<?php$image = imagecreatetruecolor(145, 30);// Image size$color = imagecolorallocate($image, 163, 197, 82);// color$bg = imagecolorallocate($image, 255, 255, 255); // background color whiteimagecolortransparent($image, $bg);// Makes Background transparent!imagefilledrectangle($image,0,0,399,99,$bg);imagettftext($image, 25, 0, 25, 25, $color, "add/to/font.ttf", "text you can get from post or somewhere");header("Content-type: image/png");imagepng($image);?>


Create a CGI script named .ttf. Add AddHandler cgi-script ttf to the Apache options for this directory (in httpd.conf or .htaccess).

Have the CGI script check the Referer field (yes, it's spelled incorrectly like that in the spec) and compare it against the address you expect it to be coming from. If it is, open the font file and write it (prepended by a couple of HTTP headers, of course). If not, redirect somewhere else.

I never checked the Referer field, but I did something sort of similar with PDFs a long time ago.

Note: if I wanted to get the font, this would only slow me down a little. But it would slow most people down a lot. I recommend making an image file with your text and putting it in your website.