我正在尝试使用'.htaccess'和'.htpasswd'来保护文件夹。
我使用http://www.tools.dynamicdrive.com/password/生成文件。
将它们复制到相应的文件夹中。
当我尝试访问受保护的文件夹时,我收到了登录提示。
输入错误的登录详细信息,发送到错误页面。
一切都很好。
现在,在没有任何更改的情况下,我重新访问该页面以尝试再次登录以访问受保护的文件夹,它只会引发错误,没有登录框。
如果我删除了.htaccess,我可以再次进入该文件夹而不会出错。
更换.htacces后,我再次收到错误,仍然没有登录框。
我尝试重新生成一组新的文件,用户/传递组合以及对.htaccess的轻微修改,只是为了尝试获得某种形式的回复。
我检查过任何字节标记,两个文件都是干净的UTF-8。
发生了什么事?为什么我不再收到提示?
在旁注中,日志应该在哪里?我设法找到的只是一些访问日志,其中没有任何用处。
服务器上的网站位置
/home/labvccom/
/home/labvccom/public_html/admin/.htaccess
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /htpasswords/.htpasswd
AuthGroupFile /dev/null
require valid-user
/home/labvccom/htpasswords/.htpasswd [user:admin |传递:密码]
admin:02yd6IWnPes66
这是我在没有登录提示时抛出错误时得到的页面
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@labvc.com.au and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at labvc.com.au Port 80
答案 0 :(得分:3)
答案 1 :(得分:0)
我认为你的.htpasswd文件的路径是错误的。如果它不是绝对的,则将其视为相对于ServerRoot。 尝试使用.htpasswd文件的绝对路径。
答案 2 :(得分:0)
您需要在要保护的文件夹中创建login / pass .htaccess ...否则该技巧将无法正常工作!我几天前创建了一个简单的php工具,为你创建登录/传递。它是我的另一个项目的一部分...所以我从我的档案中为你提取了它。注意在windows下密码被发送清楚...不是我的脚本的错误,而是Windows服务器的请求。因此,只使用unix,linux运行apache进行远程托管。将apache-ht.php放在要保护的文件夹中,然后执行它。被提示创建用户/通行证!完成后从文件夹中删除apache-ht.php。你失败是因为你试图设置相对路径。这种.htaccess需要完整的路径!我希望这会有所帮助:
apache-ht.php
<?php
############################################
# Created By Alessandro Marinuzzi [Alecos] #
# apache-ht.php - Version 1.5 - 07/04/2015 #
# WebSite: ---> http://www.alecos.it/ <--- #
############################################
if ((isset($_POST['username']) && (!empty($_POST['username']))) && ((isset($_POST['password'])) && (!empty($_POST['password'])))) {
$username = $_POST['username'];
$password = $_POST['password'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache - Username :: Password Generator</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Oswald);
@import url(http://fonts.googleapis.com/css?family=Roboto+Condensed);
html {
display: table;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: lightgray;
display: table-cell;
vertical-align: middle;
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
}
.mainbox {
border-radius: 7px;
border: 1px solid gray;
background-color: darkgray;
width: 420px;
height: auto;
margin-top: 50px;
margin-bottom: 50px;
vertical-align: middle;
text-align: center;
margin: 0 auto;
padding: 20px;
}
.title {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 24px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
vertical-align: middle;
text-align: center;
}
.save {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
border-radius: 3px;
border: 1px solid black;
background-color: darkviolet;
cursor: pointer;
box-shadow: inset -5px 5px 5px rgba(255, 255, 255, 0.15), inset 5px -5px 5px rgba(0, 0, 0, 0.15);
vertical-align: middle;
text-align: center;
padding: 10px;
}
.data {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 17px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
vertical-align: middle;
text-align: center;
}
.doit {
vertical-align: middle;
text-align: center;
}
.user {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
background-color: #006699;
border: #C0C0C0 2px solid;
vertical-align: middle;
text-align: center;
border-radius: 3px;
color: white;
width: 80px;
margin: 5px;
}
.pass {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
background-color: #006699;
border: #C0C0C0 2px solid;
vertical-align: middle;
text-align: center;
border-radius: 3px;
color: white;
width: 80px;
margin: 5px;
}
</style>
</head>
<body>
<?php
if ((substr($_SERVER['DOCUMENT_ROOT'],-1,1) == "/") && (substr($_SERVER['PHP_SELF'],0,1) =="/")) {
$path = $_SERVER['DOCUMENT_ROOT'] . substr(dirname($_SERVER['PHP_SELF']),1) . "/.htpasswd";
} else {
$path = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/.htpasswd";
}
$tmp1 = fopen(".htaccess", "w");
$tmp2 = "AuthType Basic\n";
$tmp2 .= "AuthName \"Restricted Area\"\n";
$tmp2 .= "AuthUserFile \"$path\"\n";
$tmp2 .= "Require valid-user\n";
fwrite($tmp1, $tmp2);
fclose($tmp1);
unset($tmp1);
unset($tmp2);
if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) {
$tmp1 = fopen(".htpasswd", "w");
$tmp2 = "$username:$password\n";
fwrite($tmp1, $tmp2);
fclose($tmp1);
unset($tmp1);
unset($tmp2);
} else {
$tmp1 = fopen(".htpasswd", "w");
$tmp2 = "$username:" . crypt($password,'$6$rounds=5000$usesomesillystringforsalt$') . "\n";
fwrite($tmp1, $tmp2);
fclose($tmp1);
unset($tmp1);
unset($tmp2);
}
exit("<div class=\"mainbox\">\n<span class=\"title\">Apache - Username :: Password Generated!</span>\n</div>\n</body>\n</html>");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache - Username :: Password Generator</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Oswald);
@import url(http://fonts.googleapis.com/css?family=Roboto+Condensed);
html {
display: table;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: lightgray;
display: table-cell;
vertical-align: middle;
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
}
.mainbox {
border-radius: 7px;
border: 1px solid gray;
background-color: darkgray;
width: 420px;
height: auto;
margin-top: 50px;
margin-bottom: 50px;
vertical-align: middle;
text-align: center;
margin: 0 auto;
padding: 20px;
}
.title {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 24px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
vertical-align: middle;
text-align: center;
}
.save {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
border-radius: 3px;
border: 1px solid black;
background-color: darkviolet;
cursor: pointer;
box-shadow: inset -5px 5px 5px rgba(255, 255, 255, 0.15), inset 5px -5px 5px rgba(0, 0, 0, 0.15);
vertical-align: middle;
text-align: center;
padding: 10px;
}
.data {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 17px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
vertical-align: middle;
text-align: center;
}
.doit {
vertical-align: middle;
text-align: center;
}
.user {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
background-color: #006699;
border: #C0C0C0 2px solid;
vertical-align: middle;
text-align: center;
border-radius: 3px;
color: white;
width: 80px;
margin: 5px;
}
.pass {
font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
background-color: #006699;
border: #C0C0C0 2px solid;
vertical-align: middle;
text-align: center;
border-radius: 3px;
color: white;
width: 80px;
margin: 5px;
}
</style>
</head>
<body>
<div class="mainbox">
<span class="title">Apache - Username :: Password Generator</span><br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<span class="data"><label for="username">Username:</label> <input type="text" class="user" id="username" name="username"></span><br>
<span class="data"><label for="password">Password:</label> <input type="text" class="pass" id="password" name="password"></span><br>
<span class="doit"><input type="submit" class="save" value="Create Username & Password"></span><br>
</form>
</div>
</body>
</html>