开发者

Prevent others from leaching/downloading fonts using htaccess?

Im not sure if this is a duplicate, if it is, please accept my apologies in advance. How can I prevent others from leaching/downloading my @font-face fonts (eot, svg, ttf, woff) using .hta开发者_开发百科ccess and only allowing my domain to use them?


Thanks to the guys over at the #httpd channel on IRC. I've finally found the htaccess block of code to prevent people from hotlinking to my fonts.

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
</FilesMatch>

Source: Apache Wiki.

For some reason, the code which @joshhendo provided me didn't work for both font file types and images. I'm not sure how .htaccess works, perhaps others with more experience can chime in.


You could prevent hot linking (see http://altlab.com/htaccess_tutorial.html ). This could be changed for font faces), which would allow only pages from your domain to access it. This won't stop people downloading the fonts and uploading them to their own servers, but there's nothing you can do about that.

The following code should work (it's from the URL above, but I've modified it to include the fonts you mentioned. Obviously you will need to change mysite.com to your domain name.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(eot|svg|ttf|woff)$ - [F]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜