Here it is:
RewriteEngine On
RewriteCond %{HTTP_REFERER} .*substring.* [NC]
RewriteRule /*
http://www.freegallery.biz/index2.html [R,L]
So whenever a referrer has "substring" in it, it forwards it to my entrance page,
http://www.freegallery.biz/index2.html, instead of my main page,
http://www.freegallery.biz/. The problem is that when index2.html is requested, the referrer still matches the substring and causes an infinite loop.