【问题标题】:htaccess htpasswd no prompthtaccess htpasswd 没有提示
【发布时间】:2015-04-17 22:31:50
【问题描述】:

我正在尝试使用“.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 [用户:管理员 |通行证:密码]

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

【问题讨论】:

    标签: .htaccess login prompt .htpasswd


    【解决方案1】:

    您的浏览器会记住第一次登录尝试并在 Authorization 标头中发送凭据 - 这就是您没有收到新登录提示的原因。

    尝试清除授权缓存。

    根本问题很可能正如@openscript.ch 所暗示的那样。

    【讨论】:

    • 从 chrome 中清除了我的所有浏览数据,重新加载页面,然后再次跳转到没有登录框的错误。
    • 您是否有权访问服务器错误日志?如果没有,您可以尝试在自己的机器上设置 apache 服务器。
    • 我可能有访问权限,但我不知道去哪里找。我在我的计算机上运行 XAMP,我大部分时间都在使用它,它引发了同样的问题。我尝试登录一次,然后出现永久性 500 错误。
    • 我猜想/opt/lampp/logs/error_log/var/log/apache/error_log 之类的东西。检查httpd.conf,它应该包含一个ErrorLog 行,其中包含有关记录错误的位置的详细信息。
    • 不知何故,我的 .htacces 文件有一点错字。它链接到“/htpasswords/.htaccess”而不是“/htpasswords/.htpasswd”谢谢您的帮助!
    【解决方案2】:

    我认为您的 .htpasswd 文件路径是错误的。如果它不是绝对的,则将其视为相对于 ServerRoot。 尝试使用 .htpasswd 文件的绝对路径。

    【讨论】:

      【解决方案3】:

      您需要在要保护的文件夹中创建登录名/pass .htaccess...否则该技巧将无法正常工作!几天前,我创建了一个简单的 php 工具,可以为您创建登录名/密码。这是我另一个项目的一部分……所以我从我的档案中为你提取了它。请注意,在 windows 下,密码是明确发送的……不是我的脚本的错误,而是 windows 服务器的请求。因此,仅在使用 unix、运行 apache 的 linux 的远程托管中使用它。将 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 &amp; Password"></span><br>
      </form>
      </div>
      </body>
      </html>
      

      【讨论】:

      • 这个问题是 4 年前回答的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-24
      相关资源
      最近更新 更多