首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google App Engine的静态网站404错误页面

Google App Engine的静态网站404错误页面
EN

Stack Overflow用户
提问于 2019-06-18 12:03:26
回答 1查看 758关注 0票数 0

我有一个完全静态的网站,我已经部署到Google App Engine,但我不能让它返回我的自定义404页面,就像这样的通用页面。

代码语言:javascript
运行
复制
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Not Found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Not Found</h1>
<h2>The requested URL <code>/foo</code> was not found on this server.</h2>
<h2></h2>
</body></html>

我已经尝试了我能找到的所有解决方案,但仍然不能让它工作。我试着按照this answer中的建议添加require_matching_file: true,但是没有用。我也尝试过在存储桶选项下“编辑网站配置”。

这是我的app.yaml文件。

代码语言:javascript
运行
复制
runtime: php55
api_version: 1
threadsafe: true

# Handle the main page by serving the index page.
handlers:
- url: /$
  static_files: build/index.html
  upload: build/index.html

# Handle folder urls by serving the index.html page inside.
- url: /(.*)/$
  static_files: build/\1/index.html
  upload: build/.*/index.html

# Handle nearly every other file by just serving it.
- url: /(.+)
  static_files: build/\1
  upload: build/(.*)

# all other pages are a 404
- url: /.*
  static_files: build/404.html
  upload: build/404.html

# This doesn't work either
error_handlers:
- file: build/404.html

这是我的网站的目录结构。

代码语言:javascript
运行
复制
build
│
│   index.html 
│   404.html   
│
└───blog
│   │   index.html 
│   │
│   └───post-1
│       │   index.html 
│       post-2
│       │   index.html 
│       | ...
│
└───data
│   │   blog-posts.json
│   │   projects.json
│
└───img
│   │   image-1.jpg 
│   │   image-2.jpg 
│   | ...
│ 
└───projects
│   │   index.html 
│   │
│   └───project-1
│       │   index.html 
│       project-2
│       │   index.html 
│       | ...
│ 
└───static
│   │
│   └───css
│       │   styles.css
│       js
│       │   scripts.js
│   

最终,我希望使用PHP404页面来发送正确的404标头,但现在我只能使用普通的HTML页面。

EN

回答 1

Stack Overflow用户

发布于 2019-06-23 10:43:20

这是为我工作的app.yaml文件。

代码语言:javascript
运行
复制
runtime: php55
api_version: 1
threadsafe: true

# Handle the main page by serving the index page.
handlers:
- url: /
  static_files: build/index.html
  upload: build/index.html

# Handle folder urls by serving the index.html page inside
- url: /(.*)/$
  static_files: build/\1/index.html
  upload: build/.*/index.html

# Handle other file types by just serving them
- url: /(.*\.(css|js|json|gif|eot|png|jpg|jpeg|ico|svg|xml|woff|woff2))$
  static_files: build/\1
  upload: build/.*\.(css|js|json|gif|eot|png|jpg|jpeg|ico|svg|xml|woff|woff2)$

# all other pages are a 404
- url: /.*
  script: build/404.php

其结构与问题中发布的相同,我只是将404.html更改为404.php

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56641610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档