.htaccess/.htpasswd 500 Internal Server Error

后端 未结 6 1067
暗喜
暗喜 2020-12-13 17:14

I\'m working on blocking a folder with .htaccess, which I\'ve never used before, and I\'m having some trouble. Here\'s what I have

.htaccess (located in the folder I

6条回答
  •  死守一世寂寞
    2020-12-13 17:37

    If nothing helped and you're using PHP you can make it work by putting this in your index.php (on top):

    if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
        if ($_SERVER['PHP_AUTH_USER'] != 'user' || 
            $_SERVER['PHP_AUTH_PW'] != 'pass') {
    
            header('WWW-Authenticate: Basic realm="Protected area"');
            header('HTTP/1.0 401 Unauthorized');
    
            die('Login failed!');
        }
    }
    

提交回复
热议问题