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

Dynamic subdomains with Phalcon

Does Phalcon support dynamic subdomains with modules? I woud like to create such routing, which depends on subdomain: -www.phalcon.com/ - route to module: frontend and index/index -www.backend.phalcon.com - route to module: backend and index/index.

In conclusion, I want to have two same routes, but in diffrent modules. Is it possible? I tried to create own routing and dispatcher rules, but it doesn't work. Do You have working example?



2.9k
Accepted
answer
edited Oct '15

Assuming you are using Apache web server, modify the .htaccess file inside your public folder (warning: untested):

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{HTTP_HOST} ^(([^.]*)\.)?backend\.phalcon\.com$ [NC]
    RewriteRule ^(.*)$ index.php?_url=/backend/$1 [QSA,L]

    RewriteCond %{HTTP_HOST} ^(([^.]*)\.)?phalcon\.com$ [NC]
    RewriteRule ^(.*)$ index.php?_url=/frontend/$1 [QSA,L]
</IfModule>

Then configure your routing to catch the module name.

It works perfect with some fixes, thanks!