Click to See Complete Forum and Search --> : problem with .htaccess and anti-hotlinking


nuker
02-15-2005, 11:39 AM
hello,

sorry if this forum is unappropiated to post this question and spare my life please, but i just dont understand whats happening with .htaccess in my server, im using the following script in order to prevent the hotlinking of my files


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://mydomain.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://otheralloweddomain/file/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://otheralloweddomain.com/file$ [NC]
RewriteRule .*\.(gif|htm)$ http://domaintoredirectattemptsto/ [R,NC]


All seems to be in order but it simply doesnt work, actually it does prevent hotlinking but also it prevents my own domain and site from linking my own images, the same with the other referer which is a domain i want to allow the hotlinking.

Any idea about what is wrong with this? i will thank you any help you can provide.

Thanks in advance.

Fang
02-15-2005, 01:52 PM
Ask your provider if you can do this, some providers do not allow it.

nuker
02-15-2005, 05:41 PM
Actually its supposed to allow it, thats why i wonder is not working, can you tell me please if the script is correct?

thanks.

philaweb
02-15-2005, 06:25 PM
nuker,

The code below works for me.
I guess you're missing the bit in red, which checks for empty referers.
Naturally, you need to change domain.com to the appropriate domain of yours.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC]
RewriteRule \.(jpg¦jpeg?¦gif¦png)$ http://www.domain.com/ [R,L]

BTW. Why do you want to prevent hot-linking to a HTM(L) document?