Jump to content

htaccess hotlink filter with remote "readfile"


smile

Recommended Posts

Hello, I found that this is best  remote hotlink protection htaccess script

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere.*$ [NC]
RewriteRule \.(gif|jpg|png)$ - [F]

I want to be able to allow to show the php file that has an image on another domain using the code

<?php readfile("http://mydomainhere.com/myfolder/content.php"); ?>

So I tried to include othredomain.com into the htaccess script like this

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain [NC] 
RewriteRule \.(gif|jpg|png)$ - [F]

And it seems to work, but should I also include 2 lines like for mydomainhere ?

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainhere.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain.*$ [NC]
RewriteRule \.(gif|jpg|png)$ - [F]

I must include in every subfolder or just the /myfolder/ ?

 

Link to comment
Share on other sites

Whoever wrote those didn't quite understand what they were doing. You only need one for a domain.

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mydomainhere/ [NC] 
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?otherdomain/ [NC] 
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(gif|jpg|png)$ - [F]
The third line is to allow direct access in the browser, ie. copying and pasting the URL into the address bar directly.
Link to comment
Share on other sites

Thank you for reply.

I do not want direct access using browser "copying and pasting the URL into the address bar directly".

 

So I need only these right?

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mydomainhere/ [NC] 
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?otherdomain/ [NC] 
RewriteRule \.(gif|jpg|png)$ - [F]
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.