【发布时间】:2019-11-28 07:40:00
【问题描述】:
我正在尝试在我的网站中为“找不到页面”添加自定义 404 错误页面或输入错误的 URL。我有 app.yaml 文件并使用 Go 语言。我的网站基本上在 Google App Engine 中。我检查了每一个我认为与堆栈溢出问题有关的示例。但在一些例子中,他们用 Python 或 Java 语言解释了例子,但我想用 Go 语言找到。因为我的代码是用 Go 编写的。
静态错误 404 页面已加载到服务器中,但是当我填写错误的 URL 时,它会显示错误页面未找到而不是我的自定义页面。我附上了屏幕截图,告诉你一切。
当前:- https://imgur.com/a/sGrSPyO "这就是当前显示的内容"
必填:- https://imgur.com/a/TxL7NMR“这就是我想要的”
我已阅读 google app engine 的 app.yaml 文档并尝试放置错误处理程序,但我没有找到任何解决方案。
app.yaml 文件代码
runtime: go
api_version: go1
handlers:
-url: /
static_files: www/index.html
upload: www/index.html
-url: /(.*)
static_files: www/\1
upload: www/(.*)
error_handlers:
-file: www/page-not-found.html*
这是更新后的 app.yaml 文件:
runtime: go
api_version: go1
error_handlers:
- file: /page-not-found.html
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
【问题讨论】:
标签: google-app-engine go http-status-code-404 custom-error-pages web-site-project