Forum Moderators: phranque

Message Too Old, No Replies

hotlink htaccess

this code is wrong

         

soapystar

10:55 am on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just trying to put up a simple hotlink file to allow blank referrer and selected domains but images from the selected domains are being block ed and im not sure whats wrong with the code. Images load from deep directories.

RewriteEngine On
RewriteCond %{HTTP_referer} .
RewriteCond %{HTTP_REFERER} ^http://(www\.)?mydomain.co.uk/.*$ [NC,OR]
RewriteCond %{HTTP_referer}!^http://www.anotherdomain.com [NC]
RewriteRule \.(gif¦jpg¦jpeg¦bmp)$ - [F]

jdMorgan

4:06 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The way you've got this now, the first and second RewriteConds are in conflict. The RewriteConds are [OR]'ed rather than ANDed, so the images are blocked if the domain is either "mydomain" OR NOT(anotherdomain). Plus, one is a positive match and the other is a negative match. I also recommend that you do not 'feel free' to vary spelling or case in any .htaccess code. The following should work better:

RewriteEngine On
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.co\.uk [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?anotherdomain\.com [NC]
RewriteRule \.(gif¦jpe?g¦bmp)$ - [F]

This code blocks image access if the referrer is non-blank AND NOT(mydomain) AND NOT(anotherdomain), with "www." optional in either case.

For more information, see the documentation cited in our forum charter.

Replace all broken pipe "¦" characters above with solid pipe characters before use. Posting on this board modifies them.

Jim

soapystar

5:15 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



man the number of times youve helped me out, thanks as always!

soapystar

6:33 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is there a way to specify all allowed subdomains from a single domain with out naming each one?

jdMorgan

8:08 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



 RewriteCond %{HTTP_REFERER} !^http://[^.]+\.mydomain\.co\.uk [NC]

Time to read the regular expressions tutorial on our forum charter page...

Jim

soapystar

9:40 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



reading it now.... :)