We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to change the order of the url parameters

I have the following route

$di->set('router', function() {
    $router = new Router();

     //$router->removeExtraSlashes(true);

    //Application Routes
    $router->add(
        '/online/{slug}',
        array(
            'controller'    =>  'application',
            'action'        =>  'app',
            'slug'          =>  1,
        ));

    return $router;

This route displays:

    my-domain.com/online/slug-name

What i want is invert the order of URL, and make the URL display:

    slug-name.online.my-domain.com

How i can do this?

You should be able to use setHostName: https://docs.phalcon.io/en/latest/reference/routing.html#hostname-constraints

$di->set('router', function() {
    $router = new Router();

     //$router->removeExtraSlashes(true);

    //Application Routes
    $router->add(
        '/',
        array(
            'controller'    =>  'application',
            'action'        =>  'app',
        ))->setHostName('{slug:[^\.]+}.online.my-domain.com');

    return $router;
});

In your controller:

public function appAction() {
    $slug = $this->dispatcher->getParam('slug');
}
edited Oct '15

You should be able to use setHostName: https://docs.phalcon.io/en/latest/reference/routing.html#hostname-constraints

$di->set('router', function() {
   $router = new Router();

    //$router->removeExtraSlashes(true);

   //Application Routes
   $router->add(
       '/',
       array(
           'controller'    =>  'application',
           'action'        =>  'app',
       ))->setHostName('{slug:[^\.]+}.online.my-domain.com');

   return $router;
});

In your controller:

public function appAction() {
  $slug = $this->dispatcher->getParam('slug');
}

When i do the changes which you suggest, and acess the url in browser, i am redirected to another local project alocated in my machine.

Can be a problem with my Nginx config?

server {
        listen 8080;
        server_name my-domain.com;

        index index.php index.html index.htm;

        set $root_path '/var/www/vhosts/my-domain/public';
        root $root_path;

        location / {
        allow 192.168.0.1/24;

         if (-f $request_filename) {
              break;
            }

          if (!-e $request_filename) {
              rewrite ^(.+)$ /index.php?_url=$1 last;
              break;
            }
        }

        location ~ \.php$ {
              #try_files $uri $uri/ =404;

               #include /etc/nginx/fastcgi_params;
               fastcgi_split_path_info       ^(.+\.php)(/.+)$;
               fastcgi_param PATH_INFO       $fastcgi_path_info;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

               include fastcgi_params;
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php5-fpm.sock;

        }

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

        location ~ /\.ht {
               deny all;
        }
}

I am using Linux Ubuntu, PHP-FPM and Nginx. Port 8080

edited Oct '15

Yep! As it is, server_name will resolve only for https://my-domain.com/ (it won't even match https://www.my-domain.com/ afaik)

Check out the nginx docs on how to write wildcard/regex patterns: https://nginx.org/en/docs/http/server_names.html