Google App Engine PHP Routing - Query Params

余生颓废 提交于 2019-12-12 01:58: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:


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"]);
?>


来源:https://stackoverflow.com/questions/25047515/google-app-engine-php-routing-query-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!