gpt4 book ai didi

php - 将 App Engine 子域重定向到文件夹

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:05 24 4
gpt4 key购买 nike

我在 Google App Engine 上托管一个应用程序并有多个静态页面,我想在其自己的子域上提供服务。

因此,如果域是 example.com,我希望 page.example.com/file 提供文件 example.com/page/file。如果它托管在具有重写功能的 apache 服务器上,这将是一项简单的任务。

App Engine 提供了一个 tutorial用于在 php 中模拟 mod_rewrite,但这会重定向到页面上的其他脚本,而不是静态文件,这意味着静态文件不会被视为静态文件。除了读取 php 脚本中的文件,还可以重定向到静态资源,但这意味着 URL 会为用户更改,他们会看到 example.com/page/file 在他们的地址栏中,我想避免这种情况。

在 app.yaml 中我可以做简单的重写,但只能在域之后的部分,而不是子域 -> 目录替换。

最佳答案

请注意,使用 mod_rewrite 模拟意味着您不再将文件作为静态内容提供,而是动态提供,可能会占用您的实例时间。

仍然使用静态服务的一种方法是将您的应用程序/服务映射为 example.compage.example.com 并在两个位置显示您的静态目录在您的 app.yaml 文件的 handlers 部分,如下所示:

- url: /(<file_pattern_here>)$
static_files: static/\1
upload: static/<file_pattern_here>$

- url: /page/(<file_pattern_here>)$
static_files: static/\1
upload: static/<file_pattern_here>$

但请注意,它也适用于 page.example.com/page/file。如果您不喜欢这样,您可以创建第二个服务,我们将其命名为 page,然后拆分工作:

  • 旧服务(默认?),映射到example.com 响应example.com/page/file 请求通过这个处理程序:

    - url: /page/(<file_pattern_here>)$
    static_files: static/\1
    upload: static/<file_pattern_here>$
  • 映射到 page.example.com 的新 page 服务通过以下方式响应 page.example.com/file 请求这个处理程序:

    - url: /(<file_pattern_here>)$
    static_files: static/\1
    upload: static/<file_pattern_here>$

为了使 static 目录的内容在这两个服务之间保持同步,您应该始终在这两个服务上部署并且只有一个 static 目录符号链接(symbolic link)到2 根据需要提供服务,可能是这样的:

app/
app/static/
app/default/
app/default/static -> ../static
app/page/
app/page/static -> ../static

关于php - 将 App Engine 子域重定向到文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46024326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com