Forum Moderators: phranque

Message Too Old, No Replies

Hotlinking via htacess - stops images on my site too

         

ziggle

7:50 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Hi,
I'm starting to have a bit of a problem with hot linking of images from my site and was reading a thread here:
[webmasterworld.com...]

This is my current htacess file:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]

so I added this bit of the code:

RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com\.com [NC]
RewriteRule \.(gif¦jpe?g)$ - [NC,F]

It works for the hotlinking but it's also preventing images on my site from displaying too - my forums page turned into all text :-) Do I need to add anything to include sub folders & directories on my site?

ziggle

11:59 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Okay ignore the above I got it working but have run into another problem, all images display okay except for the images in the header which will not display using Internet Explorer, my hosts tech support had a look and said:
"The problem is in Internet Explorer itself. When using Hotlink Protection, the server requires the browser to send header information (this way it is determining if the you are browsing the site, or you are just trying to browse an image from the site). Internet Explorer does not send the correct header information and that is why the images are not displaying. Unfortunately there is not much that can be done in this case - either disable hotlink protection or use Firefox."

Does anyone know if there is a work around for this? I mostly use FireFox but most of my visitors use IE :-(

EarleyGirl

4:49 am on Dec 3, 2005 (gmt 0)

10+ Year Member



Hi ziggle,

I'm far from an expert but here's one of the methods I use for a client and have no trouble viewing in IE.

SetEnvIfNoCase Referer "^https?://(www\.)?mydomain.com/" ok=1
SetEnvIfNoCase Referer "^https?://(www\.)?images.google.com/" ok=1
SetEnvIfNoCase Referer "^https?://(www\.)?google.com/" ok=1
SetEnvIfNoCase Referer "^$" ok=1
<FilesMatch "\.(gif¦png¦jpe?g)$">
order allow,deny
allow from env=ok
</FilesMatch>

(Keep in mind the pipe character comes through wrong on WebmasterWorld)

I'm not sure if it depends on your host but I have 2 clients on 2 different hosts and though for the other client I use a different code in .htaccess I can still view all images fine in IE.

Hope

jdMorgan

5:04 am on Dec 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The two methods are entirely equivalent, and in both cases should work fine.

I'd suggest you flush your browser cache (Temporary internet files) before testing and between each test, as otherwise your browser will display whatever copy of the image(s) or 403 response it last cached.

Your host is correct, to a point. If you used their 'control panel' hotlinking code, it might block blank referrers, and so might give problems with IE. But the code you posted above (both of you) allows blank referrers, so that should not be the problem. Try flushing your cache first.

If flushing your cache before and between tests doesn't help, then look to your server eeror and access logs to see if you can spot the problem.

Jim

Key_Master

8:06 am on Dec 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello jdMorgan. Long time no see. :)

ziggle

9:31 am on Dec 3, 2005 (gmt 0)

10+ Year Member



Hi,
Thanks for the replies, I'd managed to get it working using this:
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?me.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.me.com/.*$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp¦pdf¦swf)$ - [F,NC]

But I noticed yours allows google images so I'll try that one.