Question

Is it possible to create a router in Zend Framework that can match hostnames using a wildcard or regular expressions (no matter how many parts are in the hostname)?

I can create a route that matches based on a hostname

   $externalHostname = new Zend_Controller_Router_Route_Hostname(
        'ext.mysite.com', array(
            'module'=> 'external',
    ));

But what if I wanted to achieve something like this:

   $externalHostname = new Zend_Controller_Router_Route_Hostname(
        'ext.*', array(
            'module'=> 'external',
    ));

where any hostname that starts with "ext." gets routed to the "external" module, independent of how many subdomain levels the hostname has, so

  • ext.mysite.com
  • ext.test.mysite.com

would both match.

How can that be achieved?

Was it helpful?

Solution

You can not achieve this by Zend_Controller_Router_Route_Hostname. If you were intended to match only a limited number of subdomain levels (let's say 2-4), it could have worked. In this case you would add several Hostname routes for each case.

But unlimited -- I don't think so.

OTHER TIPS

What does Zend Router do ?

Answer : It basically sets and tells the Front Controller what is the current module/controller/action. And then Front controller tells Zend Dispatcher go to moduleFolder/controllerFolder and executes actionMethod.

Now you can check your above condition and set the router manually.

Now the question is where you should check and set this router?

One of the solution is :- in public/index.php file you can register it like a plugin $frontController->registerPlugin("my_router") and my_router should extends "Zend_Controller_Plugin_Abstract". Inside this my_router class constructor you can set your own router.

I would you say, just check Zend Framework basic flow ( What happens inside zend framework when make a request? )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top