Google App Engine PHP Routing - Query Params

2019-09-06 03:24发布

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?

1条回答
2楼-- · 2019-09-06 04:08

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"]);
?>
查看更多
登录 后发表回答