user3155632
user3155632

Reputation: 484

Google AppEngine PHP URL isn't redirecting(loop) properly

I am trying to depoly Baker Framwork Cloud Console and everything went well except that the url is not being redirected properly.

URL i need:

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

but the URL is getting redirected(loop) like this:

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

My 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

every thing is working fine locally.

i think i am doing some thing wrong with app.yaml rewrites.

Thanks in advance.

Upvotes: 1

Views: 810

Answers (1)

user3155632
user3155632

Reputation: 484

Thanks to @IanGSY i just figured it out and fixed it up

here is my 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

and even added this piece of code found in 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']);
}

I think this is applicable for all codeigniter apps on Google Appengine.

Upvotes: 1

Related Questions