php - error_handlers 页面在部署时不显示

标签 php google-app-engine error-handling google-cloud-platform app.yaml

我是谷歌应用引擎的新手,想在上面托管我的 php 网站。我发现有一个 error_handlers 选项可以将错误(缺少页面)重定向到自定义错误页面,但是在部署时,错误页面永远不会显示。

我已经使用 dev_appserver.py app.yaml 在本地服务器上进行了尝试,它可以工作。如果我输入一个不存在的文件,它将重定向到错误页面。但是当部署到网络上时,它就不起作用了。

这是我的 app.yaml。如果 URL 不是 php 或 html 文件,只需简单地重定向到 index.php。但是如果是php或者html文件但是没有找到,就会去error.html。

runtime: php55
api_version: 1

handlers:
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$
  application_readable: true

# Serve php scripts.
- url: /(.+\.(php\html))$
  script: \1

- url: /.*
  script: index.php

error_handlers:
  - file: error.html

在本地服务器中,它工作正常并显示错误页面。部署时,缺少 php 或 html 会出现 404 错误。 error.html 永远不会显示,即使 URL 是 (domain).com/error.html。 error.html 将显示 404 错误

我想知道是否可以将丢失的页面重定向到自定义错误页面。

最佳答案

在您的 应用程序.yaml 我认为您缺少 \- url: /(.+\.(php\html))$像这样:/(.+\.(php\\html))$error_handlers仅适用于超时、超过配额和 dos api 拒绝错误。

在我看来,您正在将所有 url 重定向到 index.php 并在那里为每个 url 创建适当的处理程序。在这种情况下,您应该使用 set_error_handler 捕获错误。 .

对于 404,我将推荐以下内容:

handlers:
 -url:/
  script: index.php

 -url:/*.
  script: 404_custom_error.php

在这种情况下,任何无法在 index.php 中处理的 url 都将由 404 自定义错误 php 脚本处理,如 app.yaml example 所示。 .

我找到了两个讨论这个话题的公共(public)问题跟踪器。第一个有关于 feature request 的信息第二个解释说 infrastructure will not intercept有效的 404 响应。

关于php - error_handlers 页面在部署时不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53946638/

相关文章:

error-handling - “This XML file does not appear to have any style information”

PHP 列表问题( undefined offset : )

php - 包装文本和滚动 div 以显示来自 MySQL 的更多内容

php - PDO执行语句超时

java - GAE JDO 中的奇数 id 序列

asp.net-mvc - 在/error Controller 中检索HTTP错误详细信息

javascript - 如何在 php 中使用内联 jquery

java - Google AppEngine 在 Codenvy 中使用 Maven 与 app.yaml 进行编译时发生冲突

java - Appengine 任务负载可以有多大?

php - 出现 MySQL 错误 "unknown column"但该列存在