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

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.

Phalcon subdomain routing

How to connect to the subdomains Phalcon:

city - in the database

I am trying to do so

$router->add('{subdomain:\w+}.{domain:.+}', array(
    'controller' => 'category',
    'action' => 'categorySearch'

but does not work.



first of all (assuming that you are using apache as webserver), you have to configure apache's virtual hosts (city1.site.com, city2.site.com ...) to make them point to the same phalcon app directory.

In your app, you should use something like beforeDispatchLoop to extract from requested url the subdomain and initialize that variable (city1, city2 ...)


Ok, I've learned something with wildcards in server config. But the second point I've suggest is still accurate !

Tip: leave a free line when using backticks `` to show code.

Eject can be, and how to redirect to the correct controller?

No, I do not need directories for applications. Subdomain will point to the city in which to search, through the controller CategoryController.

Config nginx:

server {
    listen 80;
    server_name site.com *.site.com;


<VirtualHost *:81>
        ServerName site.com
        ServerAlias *.site.com
        DocumentRoot /var/www/site/public


also, maybe it is possible to get subdomain name on application startup with beforeHandleRequest