Forum Moderators: phranque

Message Too Old, No Replies

How to deny hotlinking except for banner.jpg

         

ollybolly

11:35 am on Mar 14, 2007 (gmt 0)

10+ Year Member



I've got the following .htaccess file which also stops hotlinking to images and pdfs.

ErrorDocument 404 http://www.example.co.uk/error.html
AddType text/html .html
AddHandler server-parsed .html
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{HTTP_REFERER}!^http://(.+\.)?example\.co\.uk(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^$
RewriteRule .*\.(gif¦jpg¦pdf)$ http://www.example.co.uk/nohotlink.html [R,NC]

However I need to fix it so that http://www.example.co.uk/images/banner.jpg can be hotlinked.

Please would you advise on the fix.

jdMorgan

3:49 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, just exclude that URL from being redirected:

RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.co\.uk [NC]
[i]RewriteCond %{REQUEST_URI} !^/images/banner\.jpg$[/i]
RewriteRule \.(gif¦jpg¦pdf)$ http://www.example.co.uk/nohotlink.html [NC,R=302,L]

Note several other cleanups of unnecessary "junk" and inefficient notation in the original code.

Replace the broken pipe "¦" characters above with solid pipe characters before use; posting on this forum modifies the pipe characters.

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

ollybolly

11:37 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



Thanks that's done the trick. :-)