How to deny access to php files except for one using htaccess

I want to deny access to all php files except for one called callback.php and one called serverresult.php. I've tried the code below and in reverse order but it does not seem to work. Is there a solution please?
<Files "/some-directory/callback.php">
    Order Allow,Deny
    Allow from all
</Files>

<Files "/some-directory/serverresult.php">
    Order Allow,Deny
    Allow from all
</Files>

<Files *.php>
order deny,allow
deny from all
allow from 127.0.0.1
</Files>

Open in new window

LVL 1
ncwAsked:
Who is Participating?
 
ncwConnect With a Mentor Author Commented:
I've found that the code below works, I left out the directory structure and just specified the file names.
<Files *.php>
order deny,allow
deny from all
allow from 127.0.0.1
</Files>

<Files "serverresult.php">    
    Order Allow,Deny
    Allow from all
</Files>

<Files "callback.php">
    Order Allow,Deny
    Allow from all
</Files>

Open in new window

0
 
JelcinCommented:
Hi, (i am not 100% sure but) you could rename the other files you don't want to be accessed e.g. to "*.include" and restrict access to them.

<Files ~ "\.include$">
Order allow,deny
Deny from all
</Files

Open in new window


You could also put the files you don't wan't to be accessed outside the root directory and include them within your accessible *.php files.

But never tested my suggestions...
0
 
sjklein42Commented:
Try this:

<Files "/some-directory/callback.php">
    Order Allow,Deny
    Allow from all
</Files>

<Files "/some-directory/serverresult.php">
    Order Allow,Deny
    Allow from all
</Files>

<FilesMatch "\.php$">
order deny,allow
deny from all
allow from 127.0.0.1
</Files>

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ncwAuthor Commented:
Can the match work like a regular expression and match all php files except callback.php and serverresult.php?
0
 
sjklein42Commented:
FilesMatch uses regular expressions, but I think it would be awkward to try to exclude those specific files from the match all within a single REGEX expression.
0
 
ncwAuthor Commented:
Solved my own problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.