Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Routing with russian symbol gives 404 error

I have route, which has a Russian symbol:

      $router->add(
          "#^\/group\/([a-zа-я])#u",
          [
              "controller"    => 'group',
              "action"        => 'test',
              "type"          => 1
          ]
      );

This URL opened ok

/group/d

It gives me a 404 error

/group/д

Phalcon 3.2.4 php 5.5.9



42.4k
Accepted
answer
edited 13d ago

Phalcon is using preg_match, check if that's working at all (php5.5 seems outdated to me)

preg_match('#^\/group\/([a-zа-я])#u', '/group/d', $match1);
preg_match('#^\/group\/([a-zа-я])#u', '/group/д', $match2);
var_dump($match1, $match2);

It should work - as it is PCRE feature - u flag will make pattern interpreted as UTF-8. Only if PCRE itself is outdated badly - but I doubt that can be the case with PHP 5.5.

And really - stop using 5.5. as it is EOL for 2 years already.

It works ok

array(2) {
  [0]=>
  string(8) "/group/d"
  [1]=>
  string(1) "d"
}
array(2) {
  [0]=>
  string(9) "/group/д"
  [1]=>
  string(2) "д"
}

Phalcon is using preg_match, check if that's working at all (php5.5 seems outdated to me)

preg_match('#^\/group\/([a-zа-я])#u', '/group/d', $match1);
preg_match('#^\/group\/([a-zа-я])#u', '/group/д', $match2);
var_dump($match1, $match2);

bump... @Jurigag may have some insight

edited 13d ago

Hmmm maybe try to use newer phalcon?

$micro = new Micro();

$micro->get('#^\/group\/([a-zа-я])#u',function(){
   echo ('test');
});

$micro->handle('/group/д');

This works correctly. Same router is used both in micro and full application so it works.

Sorry guys. That's my fault. I had a parameter:

$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);

thank you all!