Google App Engine PHP路由 - 查询参数 [英] Google App Engine PHP Routing - Query Params
问题描述
我的app.yaml如下所示:
application:skilled-mark-657
版本:1
运行时:php
api_version:1
处理程序:
- url:/脚本
static_dir:脚本
- url:/ admin?dir =(。*)
脚本:admin.php
- url:/ admin
脚本:admin.php
- url: / admin / delete
script:delete.php
然后admin.php看起来像:
<?php
$ path = str_replace(/ admin,'',parse_url($ _ SERVER [ REQUEST_URI'],PHP_URL_PATH));
$ _GET ['dir'] = $ path;
var_dump($ _ GET);
当我转到 / admin?dir = someFolder 时,我被重定向返回到 / admin 。我试图让网址 / admin ,或遵循 / admin?dir =(。*)的模式。这样,在我的 admin.php 中,我可以根据给定的查询参数正确查找正确的目录。我怎么才能做到这一点?
我不太确定我完全遵循你的意思,所以请随时继续并提供更多详细信息。
如果我的理解是正确的,并且您希望所有/ admin URL由admin.php处理,并且基本上能够获得正在传递的'dir'的值,你可以试试这个:
App.yaml
应用程序:testapp
版本:1
运行时:php
api_version:1
处理程序:
- url:/ scripts
static_dir:scripts
$ b $ - url:/admin.*
script:admin.php
$ b $ - url:/ admin /删除
script:delete.php
Admin.php
<?php
echo($ _GET [dir]);
?>
My app.yaml looks like:
application: skilled-mark-657
version: 1
runtime: php
api_version: 1
handlers:
- url: /scripts
static_dir: scripts
- url: /admin?dir=(.*)
script: admin.php
- url: /admin
script: admin.php
- url: /admin/delete
script: delete.php
Then admin.php looks like:
<?php
$path = str_replace("/admin", '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$_GET['dir'] = $path;
var_dump($_GET);
When i go to /admin?dir=someFolder I'm redirected back to /admin. I'm trying to have urls that are either just /admin or follows the pattern /admin?dir=(.*). So that way in my admin.php I can properly look in the correct directory based on the given query param. How can I achieve this correctly?
I'm not quite sure I'm fully following what you're saying, so please feel free to go ahead and give more details.
If my understand is correct, and that you want all of your /admin URLs to be handled by admin.php, and basically be able to get value of 'dir' that's being passed, you could try this:
App.yaml
application: testapp
version: 1
runtime: php
api_version: 1
handlers:
- url: /scripts
static_dir: scripts
- url: /admin.*
script: admin.php
- url: /admin/delete
script: delete.php
Admin.php
<?php
echo ($_GET["dir"]);
?>
这篇关于Google App Engine PHP路由 - 查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!