【问题标题】:Custom 404 error page is generating a 500 error自定义 404 错误页面正在生成 500 错误
【发布时间】:2013-02-04 11:35:07
【问题描述】:

出于安全原因,我让所有 php 文件生成 404 错误,然后使用自定义的 404 错误页面,如下所示:

RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/
RewriteRule ^.*$ - [R=404,L]

ErrorDocument 404 /error.html

如我所愿,我访问的任何 php 脚本都会返回一个自定义 404 错误页面,但在其下方显示:

此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。

但是当我转到一个实际上不存在的页面时(比如说http://localhost/Hello/world.html),我得到了我想要的错误页面。

我很困惑,我做错了什么。另外,我希望能够为我的自定义ErrorDocument 使用 php 页面,但我不确定这是否可能。

【问题讨论】:

  • 检查服务器的错误日志以获取有关 500 的详细信息。
  • 它只是说超出了内部重定向的限制,但我不知道这是什么意思

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


【解决方案1】:

您应该尝试重定向匹配:

RedirectMatch 404 ".*\.php"

这将传递未找到错误,并抛出相应的ErrorDocument

【讨论】:

  • 它不起作用,但也许只是我解释错了。你是说用那个替换产生 404 (RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/ RewriteRule ^.*$ - [R=404,L]) 的东西吗?
  • 是的,因为重写 (mod_rewrite) 和重定向是两个不同的东西。你应该只有RedirectMatchErrorDocument
猜你喜欢
  • 2015-08-26
  • 2013-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2013-09-16
  • 2011-01-23
  • 2015-11-18
相关资源
最近更新 更多