Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess: how to restrict access to a single file by IP?

Tags:

I've look all over, but keeps running into same info that talks about directory level IP restriction, which usually looks something like this:

Order Deny,Allow Deny from all Allow from 123.123.123.123 

Is it possible to have same type of access restriction tied to a page/document?

like image 247
HeadScratching Avatar asked Aug 30 '10 21:08

HeadScratching


People also ask

How do I restrict IP address in htaccess?

Step 1: Generate the Country's IP Addresses Head to Country IP Blocks homepage. Select the countries you want to block or allow. On the Select Format section, choose Apache . htaccess Deny or Apache .


2 Answers

This will allow either someone from IP 127.0.0.1 or logged as a valid user. Stick it either in your config or .htaccess file.

    <Files learn.php>         Satisfy any         Order deny,allow         Deny from all         Allow from 127.0.0.1          AuthType Basic         AuthName "private"         AuthUserFile /var/www/phpexperts.pro/.htpasswd         AuthGroupFile /dev/null         Require valid-user     </Files> 

IP Alone:

    <Files learn.php>         Order deny,allow         Deny from all         Allow from 127.0.0.1     </Files> 

That definitely answers your question.

like image 191
Theodore R. Smith Avatar answered Oct 28 '22 03:10

Theodore R. Smith


I think the directive needs to be:

Order deny,allow 

for the answer above to work (at least for the IP Alone solution).

like image 34
Dominic Avatar answered Oct 28 '22 02:10

Dominic