We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

_url & QUERY_STRING for routing, why?

I'll state my questions first and then do the explanition later on.


  1. Why is Phalcon adding _url to QUERY_STRING and using it for routing as opposed to using REQUEST_URI and stripping query params from it?
  2. If above is how routing is done when why is it not the behavior of Phalcon 2, should I report it as a bug?
  3. I am also interested in knowing what else is being modified in global vars by Phalcon?


I have setup Phalcon2, php56 (from remi) and nginx using php-fpm and first thing I noticed that none of the routes were working. After comparision of $_SERVER with phalcon 1.3.4 that I had running on another box, I found that Phalcon 1.3.4. modifies QUERY_STRING by adding _url which is then used for routing.

To demonstrate this consider the following urls and QUERY_STRING values:

So I had to hack my nginx config to modifity QUERY_STRING as following and I am back in business

    location / {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param PHP_SELF index.php;
        fastcgi_param KAPI_ENV prod;
        # This is required for Phalcon Routing..
        fastcgi_param QUERY_STRING _url=$document_uri&$query_string;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;



Thanks for your prompot response.


It solved half of the problem, now the issue is with url encoding of REQUEST_URI. Its works fine for ASCI chars in your URL, but messes up on other chars.

So a valid param1 = é in the is passsed as %C3%A9 in the URL http://domain/controller/action/é/param2

Any work arounds for this?

Support code:

       # route
       // typical mvc url pattern
        $router->add('/:controller/:action/:params', array(
            'controller' => 1,
            'action' => 2,
            'params' => 3


      # controller
      #URL: http://domain/controller/action/é/param2
      public function suggestAction($param1, $param2)
           echo $param1 . ' should be ' . urldecode($param1);

edited Jun '15
fastcgi_param QUERY_STRING _url=$document_uri&$query_string;

Phalcon didn't modified any server parameters . You modified it