Php 将应用引擎子域重定向到文件夹

Php 将应用引擎子域重定向到文件夹,php,google-app-engine,Php,Google App Engine,我在GoogleAppEngine上托管了一个应用程序,有多个静态页面,我想在它自己的子域上提供服务 因此,如果域是example.com,我希望page.example.com/file提供文件example.com/page/file。如果托管在带有重写的apache服务器上,这将是一个简单的任务 appengine提供了一个用于在php中模拟mod_重写的脚本,但这会重定向到页面上的其他脚本,而不是静态文件,这意味着静态文件不会被视为静态文件。除了读取php脚本中的文件外,还可以重定向到静

我在GoogleAppEngine上托管了一个应用程序,有多个静态页面,我想在它自己的子域上提供服务

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

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


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

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

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

- 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>$
app/
app/static/
app/default/
app/default/static -> ../static
app/page/
app/page/static -> ../static
  • 映射到
    page.example.com
    的新
    page
    服务通过此处理程序响应
    page.example.com/file
    请求:

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