App Engine 上相同路径但不同域的不同静态文件

Different static files for the same path but different domains on App Engine

我是 运行 WordPress 网络,在 Google App Engine 标准环境 上具有自定义域(所以我不能使用 nginx 或其他东西)。

我想做的是为不同的域提供不同的静态内容,但使用相同的路径:

somedomain1.com/favicon.ico ----> static/somedomain1.com/favicon.ico
somedomain2.com/favicon.ico ----> static/somedomain2.com/favicon.ico
somedomain3.com/favicon.ico ----> static/somedomain3.com/favicon.ico

等等……

我尝试在 app.yaml URL 处理程序中使用域名,但它对我不起作用:

handlers:
- url: (http|https)://somedomain1.com/favicon.ico
  static_files: static/somedomain1.com/favicon.ico
  upload: static/somedomain1.com/favicon.ico

是否可以通过App Engine的标准环境实现?

您不能将 app.yaml URL 路由用于此目的,因为 handler url 配置不适用于 host/domain 名称部分URL,它只适用于文件路径部分。来自 Handlers element table 中的 url 行(强调我的):

url

Required element under handlers. The URL pattern, as a regular expression. The expression can contain groupings that can be referred to in the file path to the script with regular expression back-references. For example, /profile/(.*)/(.*) would match the URL /profile/edit/manager and use edit and manager as the first and second groupings.

换句话说,您的这部分配置实际上无效:

url: (http|https)://somedomain1.com/favicon.ico` 

您可以使用一个小应用程序来补充您的 WordPress 静态产品,该应用程序可以动态 根据请求 URL 中的域选择特定工件。