Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent other sites from linking to my javascript files?

I have some jquery plugins hosted on my server, but I'd like it to be available only to my visitors.. I'm paranoid other websites might just link to my js files and steal my bandwidth. How would you solve this problem?

like image 434
webnat0 Avatar asked Jul 14 '11 09:07

webnat0


2 Answers

You can use your .htaccess file to restrict the domain.

like image 178
Kevin Bowersox Avatar answered Oct 05 '22 22:10

Kevin Bowersox


Cretae a .htaccess in the root of you site folder (for apache or IIS with ISAPI_Rewrite)

Replace mysite.com with your domain remebering that all . have to be backslashed in the RewriteCond and replace with a page you want to send them to when there trying to steal your bandwidth

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\. (js|json)$ http://mysite.com/theif.txt

and add theif.txt to your site with the code below (any site trying to steal your code will send all there users to http://www.yourhtmlsource.com/sitemanagement/bandwidththeft.html lol

top.location = "http://www.yourhtmlsource.com/sitemanagement/bandwidththeft.html";

They will soon unlink your script from there page

like image 38
Barkermn01 Avatar answered Oct 05 '22 23:10

Barkermn01