Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem for disabling hot linking on server

         

georgec

11:11 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Hi;
I'm using the following code inside .htaccess to disable hot linking of images, JavaScript and CSS files on the site:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(gif¦jpg¦js¦mid¦css)$ - [F]

However I noticed in IE6 WinXP, sometimes CSS files get blocked even when served from mysite.com. It's not all the time, but there seems to be a real consistency issue. Just wondering if my code itself is correct syntax wise, and what could be the cause of the problem?

Thanks,

Dijkgraaf

11:59 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check your logs and see what refer was in the request for those files when they were blocked.

Some Proxy servers and Firewall programs strip out the Referer, and in that case your rewrite would block the request.
Also if someone views a cached page at a search site and it tries to fetch those external files from your server, they would be blocked as well.

jdMorgan

2:02 am on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Blank referrers are specifically allowed by the first RewriteCond, but I agree that a look at the log entry for a failed request might be helpful. The code looks OK, assuming that you have spaces between the "}" and "!" in both RewriteConds (this forum removes those spaces in posts, unfortunately).

Jim

georgec

4:42 am on Jul 8, 2005 (gmt 0)

10+ Year Member



Hi Morgan:
Thanks. Are you saying there should be a blank space after "{" and "¦" with the below:

{HTTP_REFERER}

and:

gif¦jpg¦js¦mid¦css

I don't think I've ever had blank spaces in them, and it worked in the past. Does it actually constitute a syntax error?

jdMorgan

5:33 am on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. In your first post,

RewriteCond %{HTTP_REFERER}!^$

should be

RewriteCond %{HTTP_REFERER} !^$

Posting the code on this board deletes the space between "}" and "!". and we need to be sure the space is there, since sometime people copy code off the forum and don't even realize that a space is required there.

The same is true for your second RewriteCond.

Jim

Tip: You can stop the forum from deleting this space by preceding the "!" with a bold-unbold or italic-enditalic tag pair in your post.

georgec

7:40 am on Jul 8, 2005 (gmt 0)

10+ Year Member



Ah ok, I guess my initial code was correct all along then. Thanks for the help.