linux - 为 Linux 中的自定义 404 错误编辑 httpd.conf 文件

标签 linux http-status-code-404 httpd.conf

我已经创建了一个自定义 404 错误页面并将其保存到此位置;

/var/www/error/error_404.php

我需要在 httpd.conf 文件中更改什么才能使此错误显示在我网站上的错误网页上?到目前为止,我已尝试将以下行添加到文件中的多个位置;

ErrorDocument 404 /error/error_404.php

然后错误页面会说类似的话;

未找到

在此服务器上找不到请求的 URL/indfdex.php/

此外,在尝试使用 ErrorDocument 时遇到 403 Forbidden 错误 处理请求。

下面是我的 httpd.conf 文件的一部分;

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# Putting this all together, we can internationalize error responses.
#
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
# our collection of by-error message multi-language collections.  We use 
# includes to substitute the appropriate text.
#
# You can modify the messages' appearance without changing any of the
# default HTTP_<error>.html.var files by adding the line:
#
#   Alias /error/include/ "/your/include/path/"
#
# which allows you to create your own set of files by starting with the
# /var/www/error/include/ files and
# copying them to /your/include/path/, even on a per-VirtualHost basis.
#

Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/var/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback

    </Directory>

#    ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
#    ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
#    ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
#    ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
#    ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
#    ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
#    ErrorDocument 410 /error/HTTP_GONE.html.var
#    ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
#    ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
#    ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
#    ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
#    ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
#    ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
#    ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
#    ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
#    ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
#    ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

</IfModule>
</IfModule>

最佳答案

你得把你的404 error.php放到apache的DocumentRoot目录下,然后测试。

感谢和问候,
阿洛克塞克

关于linux - 为 Linux 中的自定义 404 错误编辑 httpd.conf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18849121/

相关文章:

apache - 如何在 Apache httpd 中将特定 URL 路由到 http 和 https,以及将其他 URL 路由到 https

apache - 将 httpd ProxyPass 与 DirectoryIndex 结合使用

apache - Apache 中的快速 CGI : Couldn't bind unix domain socket

在 CentOS 上使用 sudo 执行 php 失败

php - ElasticSearch 同义词路径的文件权限

node.js - 在开始我的项目之前,我首先需要 docker 环境吗?

linux - awk 拆分文件给出不完整的行

AngularJS SEO 页面 404 header 状态代码

android - 构建错误 cordova 应用程序, "Error: 404 Not Found: cordova-plugin-file"

url - EmberJS : change url for loading model (ember-data)