【发布时间】:2020-11-16 16:58:43
【问题描述】:
我的问题:
由于某种原因,我的自定义 401 错误页面未在登录时显示,而仅显示通用 401 错误页面:
Unauthorized
This server could not verify that you are authorized to access the document requested.
Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't
understand how to supply the credentials required.
Additionally, a 401 Unauthorized error was encountered while trying to use an
ErrorDocument to handle the request.
现在,我的自定义 404 错误页面和其他页面都显示得很好,只是不适合 401。“error.php”(自定义错误页面)文件位于我的 public_html 目录中。
我当前在 public_html 目录中的 .htaccess 文件:
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 402 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 501 /error.php
ErrorDocument 502 /error.php
ErrorDocument 503 /error.php
ErrorDocument 504 /error.php
ErrorDocument 505 /error.php
ErrorDocument 506 /error.php
ErrorDocument 507 /error.php
ErrorDocument 510 /error.php
RewriteEngine On
DirectoryIndex .index.php .style.css .sorttable
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|zip|rar)$ - [F,NC]
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
#----------------------------------------------------------------cp:ppd
# Section managed by cPanel: Password Protected Directories -cp:ppd
# - Do not edit this section of the htaccess file! -cp:ppd
#----------------------------------------------------------------cp:ppd
AuthType Basic
AuthName "Protected 'public_html'"
AuthUserFile "/home/dark/.htpasswds/public_html/passwd"
Require valid-user
#----------------------------------------------------------------cp:ppd
# End section managed by cPanel: Password Protected Directories -cp:ppd
#----------------------------------------------------------------cp:ppd
现在我的目录受密码保护,如您在 .htaccess 中所见。我尝试了以下修复,但仍然无法显示自定义 401 错误页面:
- 在不同的目录中创建了错误页面。
- 在.htaccess文件中指定了错误页面的完整url。
- 关闭目录密码功能。
- 将错误文件扩展名更改为 .shtml。
- 在 stackoverflow 网站上尝试了许多其他代码和问题。
现在回顾一下,所有其他自定义错误页面都显示正常,只是登录时没有 401,我很困惑。
我的 cPanel 服务器信息:
Hosting Package Gold
Server Name server
cPanel Version 88.0 (build 14)
Apache Version 2.4.46
PHP Version 7.3.21
MySQL Version 10.3.24-MariaDB-cll-lve
Architecture x86_64
Operating System linux
Shared IP Address 45.95
Local IP Address 192.168
Path to Sendmail /usr/sbin/sendmail
Path to Perl /usr/bin/perl
Perl Version 5.16.3
Kernel Version 3.10.0-962.3.2.lve1.5.32.el7.x86_64
谢谢!
【问题讨论】:
-
"3.关闭目录密码功能。" - 那么你是如何尝试触发 401 的呢?这应该允许您访问 401 ErrorDocument。
-
我的意思是,我取消了
的“目录隐私”并尝试访问仍然受到保护的 。我认为受密码保护的 阻止了自定义错误页面的显示。不过没用。 -
好的,应该可以的。确保您已清除浏览器缓存。
-
我在不同的设备上使用过多个浏览器。
标签: .htaccess cpanel http-status-code-401 custom-error-pages errordocument