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:

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.



29.8k

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



29.8k

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


29.8k

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