Google AppEngine PHP URL未正确重定向(循环)

时间:2014-01-09 09:55:26

标签: php google-app-engine redirect url-rewriting

我正在尝试解密Baker Framwork Cloud Console,一切顺利,但网址没有正确重定向。

我需要的网址:

http://bake-console.appspot.com/index.php/admin/

但URL正在重定向(循环),如下所示:

http://bake-console.appspot.com/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/index.php/admin/login

我的app.yaml:

application: bake-console
version: 1
runtime: php
api_version: 1

handlers:
- url: /.*
  script: index.php

- url: /(.+)
  script: index.php

- url: /media
  static_dir: media

每件事情都在当地运作良好。

我认为app.yaml重写时我做错了。

提前致谢。

1 个答案:

答案 0 :(得分:1)

感谢@IanGSY,我只想出来并修好了

这是我的app.yaml

application: bake-console
version: 1
runtime: php
api_version: 1

handlers:
- url: /media/(.*\.(css$|js$|png$))
  static_files: media/\1
  upload: media/(.*\.(css$|js$|png$))
  application_readable: true

- url: /(.+)?/?
  script: index.php
  secure: always

- url: /.*
  script: index.php

甚至添加了Appengine Docs中的这段代码

$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// Provide mod_rewrite like functionality. If a php file in the root directory
// is explicitely requested then load the file, otherwise load index.php and
// set get variable 'q' to $_SERVER['REQUEST_URI'].
if (dirname($path) == '/' && pathinfo($path, PATHINFO_EXTENSION) == 'php') {
  $file = pathinfo($path, PATHINFO_BASENAME);
}
else {
  $file = 'index.php';
  // Provide mod_rewrite like functionality by using the path which excludes
  // any other part of the request query (ie. ignores ?foo=bar).
  $_GET['q'] = $path;
}
// Override the script name to simulate the behavior without wrapper.php.
// Ensure that $_SERVER['SCRIPT_NAME'] always begins with a / to be consistent
// with HTTP request and the value that is normally provided (not what GAE
// currently provides).
$_SERVER['SCRIPT_NAME'] = '/' . $file;

// Redirect to controller only if controller is set in URL
if(isset($_GET['q']) && $_GET['q'] != "//") {
    header("Location /index.php/" . $_GET['q']);
}

我认为这适用于Google Appengine上的所有codeigniter应用。