1

Ok so I want to protect a single webpage using .htaccess and .htpasswd

I have successfully implemented this to work on my index.php page but if I go any deeper it doesn't work.

I'm using codeigniter and here is the code from my .htaccess file

    # password-protect single file
    <Files "vAdmin.php">
    AuthName "site"
    AuthType Basic
    AuthUserFile /home/bg33qn/public_html/ci/application/views/.htpasswd
    require valid-user
    </Files>

I have both the .htaccess file and the .htpasswd file saved in:

    /home/bg33qn/public_html/ci/application/views/

Using this to protect the index page at the following location works fine:

    /home/bg33qn/public_html/ci/

Any suggestions?

Thanks

RyanUK
  • 67
  • 2
  • 12

1 Answers1

1

Do you want to password protect just one file?

<FilesMatch "vAdmin.php">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/bg33qn/public_html/ci/application/views/.htpasswd
require valid-user
</FilesMatch>

Just a tip: I hope you don't use this tool as the only security process protecting that page. It seems that page has something to do with administrators.

Updated: Create this .htaccess file where vAdmin.php is stored. So in your case, /home/bg33qn/public_html/ci/application/views/.

  • Yeh, its just the one page that needs to be password protected. I've tried that code and that doesn't work. What's strange is that it will work with files within the root of /ci – RyanUK Apr 26 '14 at 15:43
  • @user3574417 Where is the vAdmin.php stored? Make sure you have the correct path to the file. –  Apr 26 '14 at 15:45
  • vAdmin is stored at "/home/bg33qn/public_html/ci/application/views/vAdmin.php" – RyanUK Apr 26 '14 at 15:48
  • Use that as your file path. –  Apr 26 '14 at 15:49
  • so.. '' ? Because that won't work either unless i have misunderstood. – RyanUK Apr 26 '14 at 15:52
  • That is already where the .htaccess file is stored, in the same folder as vAdmin.php at '/home/bg33qn/public_html/ci/application/views/' – RyanUK Apr 26 '14 at 16:05
  • changed everything like you said but it still isn't working? @Axel – RyanUK Apr 26 '14 at 16:20
  • @user3574417 is the .htaccess file inside the folder where the vadmin.php –  Apr 26 '14 at 17:22
  • Yes, the .htaccess file is in the same folder as vAdmin.php @axel – RyanUK Apr 27 '14 at 14:17
  • @user3574417 use another password file. You mentioned you used another passports protectors directory as well. Since they're using the same password, the session could be used for the one on the vadmin.php. Or try to remove the other password protected all together to see if that helps. –  Apr 27 '14 at 17:09