Jump to content

htaccess hotlink filter with remote "readfile"


Go to solution Solved by requinix,

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/ ?

 

  • Solution

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.

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.