htaccess redirect request from domain

48 views Asked by At

I have one domain that is hotlinging my JS scripts, how to send them other script they asked with .htaccess?

I can block request with:

RewriteCond %{SERVER_NAME} ^(www\.)?exampole\.com$
RewriteRule ^ - [F]

But how to serve them another script? Lets say that they request mydomain.com/script.js and I want to send them contents of otherdomain.com/otherscript.js

1

There are 1 answers

3
anubhava On

You need to use %{REMOTE_HOST} variable to check remote host name. Use your rule like this:

RewriteCond %{REMOTE_HOST} ^(www\.)?exampole\.com$
RewriteRule ^script\.js$ http://otherdomain.com/otherscript.js [L,R=301]