Welcome! Log In Create A New Profile

Advanced

Rewrite API and spaces in parameters

Posted by nerthazrim 
Rewrite API and spaces in parameters
February 24, 2016 03:28PM
Hello guys,

We're struggling with fellow sysadmins with a lighhtpd->nginx/1.8.1 migration and rewrite rules.

We have an API and a rewrite rule like this (in nginx) :
rewrite ^/api/(.*)$ /api.php?action=$1 last;

In my PHP API, I split the "actions" in an array, with the explode PHP function.
Therefore, this:

GET /api/article/search&key=AUTHENTIFICATION_KEY&q=SEARCH_QUERY

rewrites to /api.php?action=article/search&key=AUTHENTIFICATION_KEY&q=SEARCH_QUERY

The PHP system array $_GET contains
"action'" => "article/search"
"key"=>"AUTHENTIFICATION_KEY"
"q"=>SEARCH_QUERY

So far so good... Except when there is a space in the search query, like this:

GET /api/article/search&key=AUTHENTIFICATION_KEY&q=SEARCH QUERY&blabla=lol&test=wes (last parameters given as examples)

I don't know why but in this case, the & character in the URL seems to be escaped. Therefore, my PHP $_GET array only has on field: the entire string after /api.

["action"] => "article/search&key=AUTHENTIFICATION_KEY&q=SEARCH QUERY&blabla=lol&test=wes"
and $_GET['ak'] and ['key'] are empty ...

Any idea?



Edited 1 time(s). Last edit at 02/24/2016 03:29PM by nerthazrim.
Re: Rewrite API and spaces in parameters
May 31, 2016 03:01PM
Come one guys, nobody? :(
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 104
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready