Страница ошибки статического веб-сайта 404 для Google App Engine - PullRequest
0 голосов
/ 18 июня 2019

У меня есть полностью статичный веб-сайт, который я развернул в Google App Engine, но не могу заставить его вернуть свою пользовательскую страницу 404, только такую ​​общую.

<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>

IЯ испробовал все решения, которые могу найти, но все еще не могу заставить его работать.Я попытался добавить require_matching_file: true, как рекомендовано в этом ответе , но безрезультатно.Я также попытался "Изменить конфигурацию сайта" в разделе параметров хранилища.

GAE website configuration

Это мой файл app.yaml.

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

Это структура каталогов моего веб-сайта.

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
│   

В конечном итоге я бы хотел использовать страницу PHP 404 для отправки правильного заголовка 404, но сейчас я бы согласился на простую страницу HTML.

1 Ответ

1 голос
/ 23 июня 2019

Это файл app.yaml, который работал для меня.

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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...