Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

password protect index.php and nothing else

     

drooh

7:54 pm on Jun 3, 2010 (gmt 0)

5+ Year Member



If I use

<Files index.php>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/cmslite/.htpasswd
Require valid-user
</Files>

Then when I go to my site admin.sitename.com
I get an error

But if I go to admin.sitename.com/index.php
I get the password prompt

So After searching the internet I found no answers then I tried

<Files ''>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/cmslite/.htpasswd
Require valid-user
</Files>

Then when I go to my site admin.sitename.com I get the password prompt but if I go to admin.sitename.com/index.php I am able to see the page without having to enter password

How would I get the password prompt to show up for both
admin.sitename.com and admin.sitename.com/index.php ?

And is <Files ''> correct?

Major_Payne

1:27 am on Jun 4, 2010 (gmt 0)



Maybe this would be of use:

Simple PHP Password Protect Script - [stevedawson.com...]

Or, maybe...

PHP Server Side Scripting - [webmasterworld.com...]

youfoundjake

4:22 am on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



A quick and dirty would be to set up a 301 from admin.sitename.com/index.php to admin.sitename.com/ unless you are using a CMS which may cause problems.
Also, I use cPanel, and I can password protect through the interface.
my .htaccess file ended up looking like

AuthType Basic
AuthName "Restricted Area"
AuthUserFile "/home/cmslite/.htpasswds/public_html/coffee/passwd"
require valid-user


mine did not have <files>

jdMorgan

2:26 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In this case

<FilesMatch "^(index\.php)?$">

would match both.

However, it is puzzling to me why <Files ''> works at all; The <Files> and <FilesMatch> directives apply to files, not URLs. Further, they apply to files in the current directory and in any subdirectories of this directory -- that is to say that the filename will be matched regardless of sub-directory path. And since you cannot have a blank-named file in the server filesystem, I don't know how <Files ''> can work at all.

Because of that, I also don't know how my <FilesMatch> suggestion could work, because technically it should not.

So all-in-all, I prefer youfoundjake's suggestion, as it eliminates this "mystery mode."

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month