Search code examples
apache.htaccess.htpasswd

.htaccess password protection not working with ErrorDocument 401


I have file .htpasswd under /demo/.htpasswd and having the following code

admin:71.HeoDicWfCM

And i have one more folder /demo/fb/ and here i have .htaccess file with following code

AuthType Basic 
AuthName "Secured Area" 
AuthUserFile "/demo/.htpasswd" 
require valid-user 
ErrorDocument 401 "Authorisation Required"

I am getting the popup, but when i enter username and password it shows 404 page

Any idea?


Solution

  • You don't need to create user at all. Seems like your path of htpasswd is incorrect

    Try to find full path using following code.

    <?php
    $dir = dirname(__FILE__);
    echo "<p>Full path to this dir: " . $dir . "</p>";
    echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
    ?>
    

    Use full path of htpasswd in .htaccess