【问题标题】:I appear to have 500 error page and no 404 error page, why?我似乎有 500 错误页面而没有 404 错误页面,为什么?
【发布时间】:2015-11-17 05:13:28
【问题描述】:

我正在尝试创建自定义 500 和 404 错误页面

这是我的 .htaccess 页面:

Options -MultiViews
    RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(.*)$ $1.php [L,QSA]

ErrorDocument 404 "Sorry, this page was not found"
ErrorDocument 500 "Sorry, something went wrong, try again later" 

这是一个 404 页面 http://example.com/cats - 不是页面(但它显示为 500)

这个应该是 500 http://example.com/dogs - 一个页面(因为返回的查询是空白的)但它根本不是错误消息 - 无论如何猜测这应该是 500,我希望它是

它似乎总是显示 500 而没有 404,但我不知道如何停止/修复它,有什么想法吗???

现已修复

【问题讨论】:

    标签: .htaccess http-status-code-404 custom-error-pages


    【解决方案1】:

    只有在 php 抛出异常而不是逻辑错误时才会抛出 500。返回空白结果的选择查询不会被 php 视为错误,因为有时查询将返回空白结果作为代码合法流的一部分。

    关于获得 500 而不是 400,这里 http://www.javascriptkit.com/howto/htaccess2.shtml 显示您应该转发到页面而不是尝试传递字符串。设置一个你想显示的页面,然后把 url 放到你的 htaccess 中

    像这样:

    ErrorDocument 500 /errors/serverr.html
    

    【讨论】:

    • 没有变化,遗憾的是(现在使用这个:ErrorDocument 404 /errors/404.html ErrorDocument 500 /errors/505.html)
    • 我不是 .htaccess 方面的专家,但是您的某些花哨的重写可能会干扰该过程,请尝试注释掉所有重写并尝试抛出 404
    • “此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。”向我表明这也可能只是 .htaccess 中的基本语法错误
    猜你喜欢
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-06
    相关资源
    最近更新 更多