.htaccess cPanel自定义401错误页“;不显示";

.htaccess cPanel自定义401错误页“;不显示";,.htaccess,cpanel,http-status-code-401,custom-error-pages,errordocument,.htaccess,Cpanel,Http Status Code 401,Custom Error Pages,Errordocument,我的问题: 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 ErrorDocumen

我的问题:

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
出于某些原因,我的自定义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”(自定义错误页)文件位于我的公共html目录中

公共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

谢谢

对于要提供的401 ErrorDocument,它需要是可访问的。如果HTTP身份验证后所有内容都被阻止,那么当身份验证失败时,将无法访问该内容,并且您将在默认服务器401响应中获得附加部分:

此外,尝试使用时遇到401未经授权的错误 ErrorDocument来处理请求

您需要在身份验证中“打一个洞”,并允许公众访问此文档

例如:

<Files "error.php">
    Require all granted
</Files>
为了澄清,您没有在任何页面上提供任何图像?任何包含这些文件扩展名之一的请求都将触发403禁止


更新:如果您的错误文档使用了额外的资源,那么这些文档将更容易包含在自己的子目录中(例如,
/errordocs
)-您可以只允许公众访问该子目录,而不必标识每个文件

然后在
/errordocs
子目录中创建一个附加的
.htaccess
文件,只需一行:

Require all granted

“3.关闭目录密码功能。”-那么您是如何尝试触发401的?这应该允许你访问401错误文档。我的意思是,我删除了的“目录隐私”,并试图访问仍然受到保护的目录。我以为密码保护会阻止自定义错误页面显示。没用。好吧,那应该有用的。确保已清除浏览器缓存。我已清除并在不同设备上使用了多个浏览器。“要求所有已授予的权限”似乎已起作用,但由于文件夹未包含在内,页面上似乎没有加载任何内容。但是,我可以单击缺失图像中的超链接。如何向标签添加多个文件以加载图像?是的,图像和任何其他外部资源(CSS、JS等)自然也会被阻止。但是(如上所述)您是否仍然使用
RewriteRule
指令阻止所有本地映像?如果您的错误文档使用额外的资源,那么这些文件将更容易自包含在它们自己的子目录中—您可以只允许公共访问该子目录,而不必标识每个文件。我将更新我的答案。我在.htaccess中添加了多个标记以加载基本4文件。成功了,非常感谢你,怀特先生!不客气。如果需要允许访问的文件有一个模式,则可以使用
容器,该容器提供正则表达式匹配。
容器只有基本的通配符匹配。
Require all granted