How to route multiple subdomains with hostname zend router

I need to create routing in Zend to just copy the current site URL structure, which is sadly inconsistent.

What I want to do is route the subdomain as follows:

www.site.com → static router

a.site.com and b.site.com → category controller

c.site.com and d.site.com → location controller

other subdomains → user controller

Can anyone advise me how to solve this, thanks.

UPDATE:

Thanks first to Fge, vote for your answer, it works, but I need some more tips:

  • Since I have many subdomains for each rule, there is a better way than adding rules to the loop

    foreach ($ subdomains as $ a) {$ tr = new Zend_Controller_Router_Route_Hostname ("$ A.site.com", array ('module' => 'mod', 'controller' => 'ctrl', 'param_1' => $ a)); $ Router-> addRoute ($ a, $ mp); }

  • How to combine it with another type of routing to analyze the parameters (chained?), Something like http://a.site.com/:b/:c , I want t to analyze it on param_1 (a), param_2 (b) , param_2 (c)

+5
source share
1 answer

Note: reverse match.
Routes are matched in reverse order, so be sure to identify your most common routes first.

(Zend_Controller_Router)

, , :

$user = new Zend_Controller_Router_Route_Hostname(
    ':subdomain.site.com',
    array(
        'controller' => 'user'
    )
);
$location1 = new Zend_Controller_Router_Route_Hostname(
    'c.site.com',
    array(
        'controller' => 'location'
    )
);
$location1 = new Zend_Controller_Router_Route_Hostname(
    'd.site.com',
    array(
        'controller' => 'location'
    )
);
// other definitions with known subdomain
$router->addRoute($user);   // most general one added first
$router->addRoute($location1);
$router->addRoute($location2);
// add all other subdomains

:
1) , . . , . ($request->getParam("subdomain")). , /, :subdomain :action. / , , ( ). , , :

$user = new Zend_Controller_Router_Route_Hostname(
    ':param1.site.com',
    array(
        'controller' => 'user'
    )
);
// routes "subdomain".site.com to defaultModul/userController/indexAction with additional parameter param1 => subdomain.

- , .

2) , . , , :a/:b. :

$user->chain(new Zend_Controller_Router_Route(':a/:b'));
+6

All Articles