Who gets to spot this .htaccess line bug first?

Hi all,

There’s a bug somewhere in the below code to stop hotlinking. I can’t see it but Apache thinks otherwise as when I test using a hotlink tool it can still link to the images all okay.

The only part I’ve removed and changed to “domainname” is the domain name to protect the client’s identity at this stage (both co.uk and .com).

RewriteEngine is on in the .htaccess naturally. nolinking.jpe is in the root directory.

RewriteCond %{HTTP_REFERER} !^http(s)?://([-a-z0-9]+.)?domainname.co.uk [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?domainname.co.uk [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http(s)?://([-a-z0-9]+.)?domainname.com [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?domainname.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn. [NC]
RewriteCond %{HTTP_REFERER} !yahoo. [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG|png|PNG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ /nolinking.jpe [NC,R,L]

In the good spirit of 4, 6, 8 etc. eyes are better than 2, whose eyes are really good? Won’t crash Apache but won’t do the job either as it stands. It’s got to be a char somewhere.

Thank you.

What’s even more puzzling is even the below doesn’t work and it’s taken from a hotlink protection online generator:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domainname.co.uk/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.domainname.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domainname.com/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.domainname.com/.*$ [NC] [OR]
RewriteRule .*\.(gif|GIF|jpg|JPG|png|PNG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ - [F]

The more I test it the more I believe it’s the .co.uk’s busting it up. the . between the co and uk is doing it I believe. Maybe I’m wrong but that’s what I’m leaning towards at the moment.

It would seem I got it to work in IE but not FF.

I think this Firefox not sending HTTP_REFFERER business is the problem. Don’t see why it affects images/css/js files as it does media files.

Anyone bumped into this?

So no one has a clue about this?

I believe that is the subject of discussion with your web hosting provider. Have you evven tried to contact them?

My web host doesn’t help with scripting issues.

I can confirm it works in IE and Opera, but testing hotlinking in FF will let FF still see the images.

Let’s move this to the Apache forum. You might also want to think about searching that forum for ideas.

Thanks raena,

~ServerPoint~, it has nothing to do with the host.

nsm,

It’s all in the wrist, as they say, as your code is doing what you’re telling it to do.

ANY online generator = :tdown:

Okay, the problem is that you have the [OR] flags on the early RewriteCond statements but not on the series you added. That means that the NOT anything must be true to ever reach the RewriteRule.

Further to that, you do NOT combine flags in the way that you did in your first two posts and, IF you understand

!^http://domainname.co.uk/.*$ [COLOR="Red"][NC,OR][/COLOR] == !^http://domainname.co.uk [COLOR="Red"][NC,OR][/COLOR]

you’d realize that you’re wasting CPU cycles.

May I recommend a thorough read of the tutorial linked in my signature for things mod_rewrite?

Regards,

DK