Apache Server configuration support - using htaccess to protect one file

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > December 2005 > using htaccess to protect one file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author using htaccess to protect one file
aixenv@yahoo.com

2005-12-27, 6:10 pm

im trying to find some information on how to use .htaccess and the
files directive to protect one file? i posted to another usenet group
but after looking at the posting im thinking it's rarely if ever viewed
anymore.

i have a specific php file = admin.php and im trying to make it so it's
p/w protected via htaccess, NOTE: there are other files in this
directory that i want to be accessible just as it always was, i've done
many a p/w protected dir in apache, but i have never used htaccess to
block access to a specific file while leaving all the other files in
that same dir accessible.

my htaccess looks like this

<Files "admin.php">
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/httpd/htpasswd
Require valid-user
</Files>

the perms on both htpasswd and .htaccess are 644 with root:root however
the directory that has this admin.php file just gives a 403 permission
denied, not sure what im doing wrong, the only reference i found to
someone trying to do this, was basically like i have tried to
accomplish it, any help is appreciated. thank you

John Bokma

2005-12-27, 6:10 pm

aixenv@yahoo.com wrote:

> im trying to find some information on how to use .htaccess and the
> files directive to protect one file? i posted to another usenet group
> but after looking at the posting im thinking it's rarely if ever viewed
> anymore.


I did this in the past by checking if the Authorization header is present,
if not, replying with a 401. If it is, check the credentials, and if not
ok, 401. If ok, the script can be used.

http://www.zend.com/zend/tut/authentication.php

HTH,

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Purl Gurl

2005-12-27, 8:55 pm

aixenv wrote:

Topic: protect a single file via authentication

> my htaccess looks like this


> <Files "admin.php">
> AuthType Basic
> AuthName "Restricted Files"
> AuthUserFile /etc/httpd/htpasswd
> Require valid-user
> </Files>


Your syntax is correct. Use a full path for AuthUserFile.

> the perms on both htpasswd and .htaccess are 644 with root:root however
> the directory that has this admin.php file just gives a 403 permission denied


Your 403 appears unrelated to your authentication. Might be your directory is outside
your document root and needs to be aliased. Might be permission is denied for your
directory in your httpd configuration file.

Test access without your .htaccess file. Then test with your .htaccess file.

Purl Gurl
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com