Search code examples
phpzend-frameworkzend-routezend-router

Hostname and regex-based route in Zend Framework


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?


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.