Forum Moderators: phranque

Message Too Old, No Replies

Block referers with a dash

         

john25

4:30 pm on Dec 1, 2008 (gmt 0)

10+ Year Member



Hi,

I`m using this to prevent hotlinking but it isn`t working with referers that contain a dash "-"

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.tld/.*$ [NC]
RewriteRule .*\.(jpe?g¦gif¦png¦js¦css¦exe¦msu¦cab¦zip¦7z¦rar)$ - [F,L]

Is it possible to check for referers containing a dash and block them also?

Thanks for your help
John

wilderness

6:07 pm on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Believe the following is what your looking for?

RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule .* - [F]

To use for refers, simply change the portion of first line to
{HTTP_REFERER}

Please keep in mind that as a general rule, blocking refers in such a manner is a BAD practive and will deny many innocents.

jdMorgan

11:28 pm on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem may be that Apache shows totally-blank referrers as a quoted hyphen (as "-") in the raw log files.

Also, the way this rule is constructed, it says, "block media file requests unless the referrer is non-blank and is NOT a specific domain" (almost always your own domain).

So, what blocking function do you want to add? -- "It doesn't work" tells us nothing about your goal or your expectations.

Just as a performance tweak, I'd suggest the following minor changes.


RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^(www\.)?domain\.tld/ [NC]
RewriteRule \.(jpe?g¦gif¦png¦js¦css¦exe¦msu¦cab¦zip¦7z¦rar)$ - [F]

Note that the function of the rule is completely unchanged, it will just run a bit faster.

Jim