Forum Moderators: phranque
I think you are close, but his may be more effective:
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} ^!(www.)?yoursite\.com$
RewriteCond %{HTTP_HOST} ^.+\.ru [OR]
RewriteCond %{HTTP_REFERER} ^.+\.ru
RewriteRule . - [F]
This should work if your site is being framed, or if there are referers coming from sites with the .ru extension...
The first condition checks to see if there is a referer. If there is not, the ruleset will fail.
The second condition checks to see if you are the referer. If your site is, the ruleset will fail. (www.)? makes the www portion of your URL optional.
The idea is to keep your performance, so if the rule set fails as soon as you are the referer, only external referers will be checked by the remaining conditions.
The third and fourth condition check to see if either the host (framing) or the referer are from anything .ru, and if they are, returns forbiden.
By not formally closing the line with $ 'and anything else' is assumed.
You might need to 'tweek' it a little, but as it is it's fairly close.
Please, keep in mind this will not block any search engines or browsers without referers.
Hope this helps.
Justin
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} ^!(www.)?yoursite\.com$
RewriteCond %{HTTP_HOST} ^.+\.ru [OR]
RewriteCond %{HTTP_REFERER} ^.+\.ru
RewriteRule . - [F]
The second RewriteCond should, I think, be written as:
RewriteCond %{HTTP_REFERER} ^(https?://)?!(www\.)?yoursite\.com
However, unless the site you're running is a .ru domain, this can be vastly simplified:
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} ^(https?://)?.+\.ru($¦/)
RewriteRule . - [F,L]
Additionally, mod_rewrite is actually overkill for this, since the same thing can be accomplished using SetEnvIfNoCase:
SetEnvIfNoCase Referer ^(https?://)?.+\.ru($¦/) ban
Order allow,deny
Allow from all
Deny from env=ban