Forum Moderators: phranque
Tap, tap, tap, I'm drumming my fingers impatiently waiting for your edited post! :)
[edited by: DaveAtIFG at 8:02 pm (utc) on Sep. 28, 2003]
Hi everyone,
I have written this little .htaccess to stop people from direct linking to my site:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif夸pg夸peg在mp如ng)$ [mydomain.com...] [R,NC]
This code works perfectly, but this picture isn't appriciated by some people. So I wanted to add 1 domain with an extra RewriteCond/RewriteRule so that they don't get to see the picture, but a 403 Error. So I made this piece of code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif夸pg夸peg在mp如ng)$ [mydomain.com...] [R,NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?someothersite.com(/)?.*$ [NC]
RewriteRule .*\.(gif夸pg夸peg在mp如ng)$ [F,NC]
But it doesn't work. Could someone please tell me what I'm doing wrong? Thanks a lot!
FirstBorn
for one thing, you need to exclude that domain in the same way that you exclude your domain... so at least, you need to copy that rule into the previous set...
Options +FollowSymlinks
RewriteEngine on # grab blank referrers
RewriteCond %{HTTP_REFERER}!^$
# don't block my domain
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com(/)?.*$ [NC]
# don't block someother domain
RewriteCond %{HTTP_REFERER}!^http://(www\.)?someothersite.com(/)?.*$ [NC]
# send them something they don't want
RewriteRule .*\.(gif夸pg夸peg在mp如ng)$ http://mydomain.com/some_insulting_image.jpe [R,NC]
# check for someother domain
RewriteCond %{HTTP_REFERER} ^http://(www\.)?someothersite.com(/)?.*$ [NC]
# send them a failure on the pic
RewriteRule .*\.(gif夸pg夸peg在mp如ng)$ [F,NC]
[edit] oops - fix error [/edit]