php - error_handlers 页面在部署时不显示
问题描述
我是谷歌应用引擎的新手,想在上面托管我的 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 错误
我想知道是否可以将丢失的页面重定向到自定义错误页面。
解决方案
在您的app.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 示例所示。
我找到了两个讨论这个话题的公共问题跟踪器。第一个包含有关功能请求的信息,第二个说明基础设施不会拦截有效的 404 响应。
推荐阅读
- reactjs - 反应巴比伦装载机 OBJ 文件
- assembly - ARM64 汇编中的可变大小内存空间
- javascript - 如果 Web 浏览器大小减小或处于窗口模式,如何隐藏 iframe
- reactjs - 使用加载更多按钮获取更多数据而不会丢失以前的数据
- java - 问题 javax.persistence.EntityNotFoundException
- python - 使用python批量更新postgres中的单行
- php - Woocommerce“您的购物车目前是空的”但仅在预览模式之外?(自定义结帐表格)
- c# - 无法找到/理解如何在 Unity 中为我的 PlayerController 脚本使用新输入系统
- google-apps-script - 每次有人访问谷歌文档和/或使用应用程序脚本复制它时创建查看历史记录
- azure - 从 terraform 创建服务主体时获取权限不足以完成操作错误