Forum Moderators: phranque

Message Too Old, No Replies

.htaccess problems

Disabling Hotlinking

         

Technel

2:13 am on Mar 29, 2004 (gmt 0)

10+ Year Member



Hello,

I have tried several tutorials to disable hotlinking using .htaccess, but for some reason it isn't working. Here is the code in my .htaccess:

ErrorDocument 400 http://example.cc/error.php
ErrorDocument 401 http://example.cc/errorp.php
ErrorDocument 403 http://example.cc/errorp.php
ErrorDocument 404 http://example.cc/error.php
ErrorDocument 500 http://example.cc/error.php
Options -Indexes
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.cc(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp¦png)$ http://example.cc/img/remote.gif [R,NC]

It is not blocking remote linking. My test image is:

[example.cc...]

Can someone please point out what I'm doing wrong? Thanks,

- Technel

[edited by: jdMorgan at 3:02 pm (utc) on Mar. 30, 2004]
[edit reason] Removed URLs per TOS [/edit]

jdMorgan

3:14 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Technel,

Welcome to WebmasterWorld [webmasterworld.com]!

The likely main problem is that you need to add another option and enable the rewrite engine. However, there are several other problems, especially with the ErrorDocument directives. See the Apache documentation [httpd.apache.org] warning about using canonical URLs in ErrorDocument!

Here's how I'd recommend you code it:


ErrorDocument 400 /error.php
ErrorDocument 401 /errorp.php
ErrorDocument 403 /errorp.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.cc [NC]
RewriteRule %{REQUEST_URI} !^/img/remote\.gif$
RewriteRule \.(gif¦jpe?g¦bmp¦png)$ /img/remote.gif [NC]

This code will block requests that have a non-blank referrer that is not your own domain.

Also, always flush your browser cache between tests when working with redirects, otherwise the results may appear to be incorrect.

Jim

lasko

12:16 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



Well I have set up a testing server on my main computer using Apache on windows xp.

I got all the corrects mods installed tested and worked.

However it won't work on my main hosting account and now I find out they don't allow mod_rewrite on the servers.

Is this normal?

I have many images that are hot linked and using my bandwidth. Perhaps the hosting company wants my bandwidth used so I have to purchase more?

So frustraiting, actually managing to get it right and working perfectly but then unable to use it.

:(

jdMorgan

4:15 am on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Block hotlinking without mod_rewrite: [webmasterworld.com...] (See the first post)

Jim

lasko

8:24 pm on Apr 2, 2004 (gmt 0)

10+ Year Member




Thanks Jim

I have done that now and works great, had a few teething problems but got it right.

Apparently our host will soon allow mod_rewrite :)

One thing I have noticed is that Google Images is not too bad but Yahoo I have found to be linking to images when people perform an Image search. Google downloads the image once and stores on their own server.

I have over 600 pages and 30,000 unique visitors per month which is using up 7500MB of transfer per month is this to be expected?

I am now looking at blocking certain User-Agents that ignore my robots.txt.

Carefully watching my error and access logs to ensure I do it safely. :)