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

Phalcon subdomain routing

How to connect to the subdomains Phalcon:

city1.site.com
city2.site.com
city3.site.com
...
cityN.site.com
city - in the database

I am trying to do so

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

but does not work.



43.9k

Hi,

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 ...)



43.9k

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;
    ...

Apahce:

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


43.9k

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