【问题标题】:How to configure app.yaml on GAE with PHP如何使用 PHP 在 GAE 上配置 app.yaml
【发布时间】:2021-03-25 00:28:39
【问题描述】:

为了在 PHP 代码中重定向,我在 GAE 上配置 app.yaml 时遇到了困难。在 index.php 中按下提交按钮后,我想重定向到thanks/thanks.html 目录中名为thanks.html 的另一个HTML 页面。但是,它使用当前设置从 index.php 重定向到 index.php。我认为 PHP 代码没有检测到我的 Thanks.html。所以我想问你我的 app.yaml 有什么问题,我应该使用 dispatch.yaml 吗?太感谢了 。除了重定向,其他功能都正常。

我的目录结构是

index.php(only the part of redirect to thanks.html)

header("Location: ./thanks/thanks.html");
exit();
app.yaml

runtime: php72
handlers:
- url: /(.*\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$

- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: .*
  script: auto
  http_headers:

- url: /thanks
  static_dir: /thanks

env_variables:
        SENDGRID_API_KEY: "*********"
        DEVELOPER_EMAIL: "********" 

【问题讨论】:

    标签: php google-app-engine


    【解决方案1】:

    您需要部署 front controller 来处理 App Engine 中的所有请求路由。使用以下代码进行部署:

    index.php

    <?php
    header("Location: ./thanks/thanks.html");
    exit();
    switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
        case '/':
            require 'index.php';
            break;
        case 'thanks/thanks.html':
            require 'thanks.html';
            break;
        default:
            http_response_code(404);
            exit('Not Found');
    }
    ?>
    

    【讨论】:

    • 非常感谢。我尝试添加您的代码并将其重定向到同一页面 index.php。
    • 什么意思?它应该始终重定向到thanks.html
    • 对不起。我在我的代码上发现了错字。让我再检查一下。
    • 如果遇到thanks.html 未找到,请转到- url: /thanks 中的app.yaml,将static_dir 值从/thanks 更改为仅限thanks
    • 如果您对此问题有其他顾虑或错误,请告诉我。
    猜你喜欢
    • 2013-10-06
    • 1970-01-01
    • 2014-07-25
    • 2011-06-28
    • 2013-03-28
    • 2011-11-10
    • 2012-05-03
    • 2013-10-22
    • 2011-10-16
    相关资源
    最近更新 更多