All paths lead to index view

I decided to try something new and installed Phalcon on Nginx (haven't used this before) and started following the Tutorial 1: Let’s learn by example.

I have created the signup link to the index page. When I click that link I'm taken to page localhost/signup but the the index page is shown (I have created app/controllers/SignupController.php and app/views/signup/index.phtml).

No matter what I write to browser's address bar, it always leads to the same result. If I type in 'localhost/some_url_that_does_not_exist' it still shows the app/views/index/index.phtml.

Dir tree:


Nginx conf (/etc/nginx/sites-available/default):

server {

    listen   80;
    server_name localhost;

    index index.php index.html index.htm;

    set $root_path '/var/www/phalcon/public';
    root $root_path;

    location / {
        try_files $uri $uri/ /index.php;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;

    location ~ /\.ht {
        deny all;


Bootstrap (/var/www/phalcon/public/index.php):


try {

    //Register an autoloader
    $loader = new \Phalcon\Loader();

    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();

    //Setting up the view component
    $di->set('view', function(){
        $view = new \Phalcon\Mvc\View();
        return $view;

    //Handle the request
    $application = new \Phalcon\Mvc\Application($di);

    echo $application->handle()->getContent();

} catch(\Phalcon\Exception $e) {
     echo "PhalconException: ", $e->getMessage();

There must be some small beginner's error somewhere.


I added router to the DI

$di->set('router', function(){
        require __DIR__.'/../app/routes/routes.php';
        return $router;

and a route file app/routes/routes.php


$router = new \Phalcon\Mvc\Router();

$router->add("/", array(       
    'controller' => 'index',
    'action' => 'index',

/*$router->add("/:controller", array(       
    'controller' => '1',
    'action' => 'index',

$router->add("/signup", array(       
    'controller' => 'signup',
    'action' => 'index',


echo 'Testing ', $_SERVER['REQUEST_URI'], '<br>';

//Check if some route was matched
if ($router->wasMatched()) {
    echo 'Controller: ', $router->getControllerName(), '<br>';
    echo 'Action: ', $router->getActionName(), '<br>';
} else {
    echo 'The route wasn\'t matched by any route<br>';
echo '<br>';

but nothing changes. If I uncomment the testing part of the router file it claims to be using SignupController but it still shows the index page (even if the browser's address bar says we're on localhost/signup).

If I fix the router a bit

$router->add("/", array(       
    'controller' => 'signup',
    'action' => 'index',

the signup page is shown. So at least the router file is read :)

But still the problem remains.


$router->handle() must not be called manually, a proper routes.php looks like this:


Thank you for the proper routes.php but it didn't change anything.

Now my routes.php looks like this


$router = new Phalcon\Mvc\Router(false);

$router->add('/signup', array(       
    'controller' => 'signup',
    'action' => 'index'

$router->add('/', array(       
    'controller' => 'index',
    'action' => 'index'

return $router;

So for some reason the IndexController is read always, no matter what the url in browser's address bar says. Even if I try to go to a page that doesn't exist.

Would this be a problem in the Nginx config?


Yes, may be. Your nginx config does not create spesial variable url. Phalcon read parameters, including routes, from this variable. Directive


solve this problem. Or change nginx config to create url parameter. This issue is covered in detail in the documentation.


Thank you, Oleg!

That solved the problem.