Forum Moderators: phranque

Message Too Old, No Replies

htaccess anti-hotlink doesnt work

hotlink code doesnt work

         

john1000

1:26 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Hi guys,

I never thought i would be back so soon but this time its not about my site but a friend from the u.k

he discovered someone was hotlinking an animated under construction image and he was realy pissed so i said well thats easy solved .
So confident as i was i put in the codes i used some time ago.
guess what..it didnt worked.
I tried another one and another and even this one below i grabbed from the forum here..

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://website.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.website.co.uk/.*$ [NC]
RewriteRule .*\.(gif¦GIF¦jpg¦JPG)$ [website.co.uk...] [R]

And even this doesnt work!
It turns his site into 500 server error.

Believe it or not but ive tried about 8 versions and one of them actualy prevented the hotlinking but i couldnt get the theft image to show,thats why i continued searching.

The only thing in the htaccess is:

#DirectoryIndex index.html index.php
php_flag output_buffering on
php_flag magic_quotes_gpc ON

The DirectoryIndex line is temporary taken out as you see "#" cause it gave errors...

Anyone have clue whats going on?
Is the u.k that different?

jdMorgan

1:42 am on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the relevant entries from your server error log. For 500-Server Errors, it will often tell you exactly what is wrong.

Jim

john1000

2:00 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Hello jim,

Well i dont have access to any panel or the account itself so all i can access or look at is his ftp and i dont see any created error_log file so that doesnt help..

Any lines we can try?

jdMorgan

2:19 am on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can shoot in the dark all night long, and never hit anything. If you cannot access your server logs, it's time to move to a 'real' server if you want to do server-side coding.

(You could not pay me enough to host on a server with no log file access...)

The code you've posted appears to be auto-generated -- It is inefficient and contains unnecessary regex tokens. So I'll take *one* shot in the dark, and suggest:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?website\.co\.uk
RewriteCond %{REQUEST_URI} !/images/theft\.jpg$
RewriteRule \.(gif¦jpg)$ http://www.website.co.uk/images/theft.jpg [NC,R=302,L]

Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this board modifies that character, making it invalid for use in server config files.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

john1000

2:41 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Well that didnt worked,but gave no error either.
And Jim...i said in first story that its not my website.. :)

The htaccess looks like this:

DirectoryIndex index.html index.php
php_flag output_buffering on
php_flag magic_quotes_gpc ON

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?website\.co\.uk
RewriteCond %{REQUEST_URI}!/images/theft\.jpg$
RewriteRule \.(gif¦jpg)$ [website.co.uk...] [NC,R=302,L]

but nothing happens and hotlinking is allowed...

Pfui

5:42 am on Feb 13, 2006 (gmt 0)

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



One obvious-but-you-never-know Q:

Are you sure mod_rewrite is available on the server?

(You could not pay me enough to host on a server with no log file access... ditto no command line, no mod_rewrite...)

john1000

12:50 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



Yes cause like i said in first post...."one of them actualy prevented the hotlinking but i couldnt get the theft image to show".....

So seems to me mod rewrite works.

jdMorgan

1:31 pm on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're sure mod_rewrite is available, you can simplify the the code for testing:

RewriteCond %{REQUEST_URI} !/images/theft\.jpg$
RewriteRule \.(gif¦jpg)$ http://www.website.co.uk/images/theft.jpg [NC,R=302,L]

That will replace *all* images on the site with theft.jpg, IF you:

  • Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this board modifies that character, making it invalid for use in server config files.

  • Flush your browser cache before testing the new access-control code, and after any "successful" attempt to view the 'real' images.

    If that works, then add the other two RewriteConds one at a time, flushing your browser cache each time, and see where you have a problem. Assuming you're using IE, flush using Control Panel -> Internet Options -> Temporary Internet Files -> Delete Files, and do select the Delete all offline content option.

    Jim
    [edit] Fixed space between "}" and "!" [/edit]

    [edited by: jdMorgan at 2:23 pm (utc) on Feb. 13, 2006]

  • john1000

    2:03 pm on Feb 13, 2006 (gmt 0)

    10+ Year Member



    Well Jim i hoped to more positive but even with your code it goes into 500 internal server error.
    But if i look at his phpinfo i dont see mod_rewrite?
    but yesterday im sure i got one code working preventing the hotlink...