homepage Welcome to WebmasterWorld Guest from 54.161.175.231
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
password protect index.php and nothing else
drooh




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

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




msg:4146691
 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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved