Forum Moderators: phranque

Message Too Old, No Replies

How to restrict file download to certain ip by htaccess rewrite

         

Egycode

3:59 pm on Nov 1, 2011 (gmt 0)

10+ Year Member



Hello,

I need help to restrict file download to specific ip via htaccess rewrite, I use this rules in the .htaccess file but it don't work,

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^xx\.xx\.xx\.xx [NC]
RewriteRule \.*$ http://www.example.com [NC,R=302]

I use cpanel, apache with nginx admin, could nginx cause this issue? htaccess rewrite working like this,

RewriteRule ^.*$ download.php&%{QUERY_STRING}

Edit: I want to restrict all kind of downloads, regular and by download accelerators.

Thanks.

phranque

4:19 am on Nov 4, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Egycode!

HTTP_HOST is the hostname of the requested url.
i think you want to use REMOTE_ADDR which would be the IP of the requestor.

lucy24

4:54 am on Nov 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



... and once you've done that, you'll have to deal with

RewriteRule \.*$ http://www.example.com [NC,R=302]


which appears to say "the request might end with one or more literal periods, or it might not". You don't need [NC] here since, ahem, periods don't come in upper-case and lower-case forms. What you do need is [L]. And always, always [R=301] unless it really truly is a temporary redirect and things will be back to normal in a week or two.