如何在 app.yaml 中正确路由目录呼叫?
How to route directory calls correctly in app.yaml?
我想模仿这个 .htaccess 重写,在 Google App Engine app.yaml 中使用 PHP:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ query.php?q= [QSA,NC,L]
</IfModule>
我已经这样做了:
runtime: php55
api_version: 1
threadsafe: true
handlers:
# mod_rewrite by forwarding the requests to query.php?q=...
- url: /services/(.+)
script: services/query.php?q=
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg|ico|svg))$
static_files:
upload: .+\.(gif|png|jpg|ico|svg)$
application_readable: true
- url: /(.+\.(html))$
static_files:
upload: .+\.(html)$
application_readable: true
# Serve php scripts.
- url: /(.+\.php)$
script:
- url: /
static_files: index.html
upload: index.html
application_readable: true
但是结果总是找不到错误:
"POST /services/login HTTP/1.1" 404
我认为管理员没有抓住它。有什么正确的线索吗?
我不认为你可以这样做 - script:
语句不是用于指定完整的 URL(及其查询字符串),它只是用于指定脚本的路径。来自 Handlers element:
script
Optional. Specifies the path to the script from the application root
directory:
...
handlers:
- url: /profile/(.*)/(.*)
script: /employee//.php # specify a script
您可以通过在第一个处理程序中将 script: services/query.php?q=
替换为 script: services/query.php
来轻松确认这一点。如果 services/query.php
脚本开始被调用,这意味着模式匹配工作正常,问题是脚本规范 - services/query.php?q=
不是有效的脚本文件路径。
我想模仿这个 .htaccess 重写,在 Google App Engine app.yaml 中使用 PHP:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ query.php?q= [QSA,NC,L]
</IfModule>
我已经这样做了:
runtime: php55
api_version: 1
threadsafe: true
handlers:
# mod_rewrite by forwarding the requests to query.php?q=...
- url: /services/(.+)
script: services/query.php?q=
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg|ico|svg))$
static_files:
upload: .+\.(gif|png|jpg|ico|svg)$
application_readable: true
- url: /(.+\.(html))$
static_files:
upload: .+\.(html)$
application_readable: true
# Serve php scripts.
- url: /(.+\.php)$
script:
- url: /
static_files: index.html
upload: index.html
application_readable: true
但是结果总是找不到错误:
"POST /services/login HTTP/1.1" 404
我认为管理员没有抓住它。有什么正确的线索吗?
我不认为你可以这样做 - script:
语句不是用于指定完整的 URL(及其查询字符串),它只是用于指定脚本的路径。来自 Handlers element:
script
Optional. Specifies the path to the script from the application root directory:
... handlers: - url: /profile/(.*)/(.*) script: /employee//.php # specify a script
您可以通过在第一个处理程序中将 script: services/query.php?q=
替换为 script: services/query.php
来轻松确认这一点。如果 services/query.php
脚本开始被调用,这意味着模式匹配工作正常,问题是脚本规范 - services/query.php?q=
不是有效的脚本文件路径。