.htpasswd and .htaccess - internal server error

后端 未结 4 1621
死守一世寂寞
死守一世寂寞 2021-01-04 00:51

I want to password protect my website, but as soon as I add in the .htpasswd and .htaccess files I get a server error:

Internal Server Error

相关标签:
4条回答
  • 2021-01-04 01:07

    According to AuthUserFile, you must supply the complete path to your password file, not the relative path from DocumentRoot, if it is absolute (i.e. starting with a slash).

    The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.

    Note that ServerRoot is not DocumentRoot.

    If DocumentRoot is /var/www and the password file is /var/www/webroot/.htpasswd, you must say

    AuthUserFile /var/www/webroot/.htpasswd
    

    in your .htaccess file.


    You can find out about the absolute path with a small PHP script, e.g.

    <?php
    echo "Absolute path: ", getcwd();
    

    Put this in the directory, where you want to locate the .htpasswd file, and call it with http://www.example.com/path/to/test.php

    Don't forget to remove the script, when you're done.


    Said that, you shouldn't put your password file anywhere accessible in your DocumentRoot. Better put it in some place not accessible from the web, i.e. /etc/apache2/htpasswd or wherever it suits you.

    0 讨论(0)
  • 2021-01-04 01:07

    Two things come to mind.

    1. Is .htpasswd readable by the web server user?

    2. Do you know if Apache is set with AllowOverride all to allow .htaccess to operate as intended?

    0 讨论(0)
  • 2021-01-04 01:10

    Major reason of this error is the "AuthUserFile" path. I was having this same issue and i solved it by going in cpanel. By protecting your folder in cPanel, it automatically detects the htpasswd file.

    Go to cPanel->Password Protect Directories->Define directory and then create a user. Hope this help you.

    0 讨论(0)
  • 2021-01-04 01:15

    All of the standard answers (full path, correct format, etc) weren't working for me. After a lot of tracking down I found that the permissions on the parent folder were insufficient, so even though the path in .htaccess was correct and the permissions on the file were rw-r-r, still no go because the parent was rwx-rw--. That can be tough to track down on a host that limits access to up stream folders.

    0 讨论(0)
提交回复
热议问题