首页 > 解决方案 > 在 GAE 上托管一个包含一些 php 文件的大部分静态网站

问题描述

我在 Google App Engine 上托管了一个主要是静态的网站,并且似乎在设置我的 app.yaml 时遇到了一些麻烦。要么就是这样,要么我的文件路径已关闭。我看过其他帖子,其中混合静态和动态内容似乎会带来一些麻烦,所以我决定这样设置我的文件:

Site (Root Folder)
    app.yaml
    contact (Dynamic page)
        -index.php
    projects (Nothing in here yet but will group dynamic content here)
    README.md
    www (Static files)
        -blog
        -css
        -images
        -index.html
        -js

试图在我的主页上创建链接

/www/index.html

到我的联系页面

/contact/index.php

我应该将您从 index.html 引导到 index.php 的文件路径是

../contact/index.php

下面是我的 app.yaml

runtime: php55
api_version: 1

handlers:
    - url: /
      static_files: www/index.html
      upload: www/index.html
      mime_type: home
      secure: always

    - url: /(.*)
      static_files: www/\1
      upload: www/(.*)
      secure: always
      application_readable: true

    - url: contact/index.php
      script: /contact/index.php
      secure: always

不知道我在这里做错了什么。我尝试了几种不同的文件路径,但根本无法显示页面。当我单击应该将我带到联系人页面 (index.php) 的链接时,我收到 404 错误。

标签: phphtmlgoogle-app-enginefilepathapp.yaml

解决方案


contact/index.php您的通配符包罗万象的处理程序在到达其正确的处理程序之前正在抓取。另外,您缺少前导斜杠。 mimetype: home是不恰当的。试试这个:

runtime: php55
api_version: 1

handlers:
- url: /contact/index.php
  script: /contact/index.php
  secure: always

- url: /
  static_files: www/index.html
  upload: www/index.html
  secure: always

- url: /(.*)
  static_files: www/\1
  upload: www/(.*)
  secure: always
  application_readable: true

推荐阅读