So I want to create a Zend_Controller_Router_Route_Hostname
that matches the following:
- example.com
- www.example.com
- stage.example.com
- dev.example.com
- andrew.dev.example.com
- joe.dev.example.com
I can't seem to figure out how to create a route that can match all these things. There can be multiple subdomains before "example.com", so everything before it doesn't really matter. Here's what I have so far:
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(':sandbox.:environment.example.com', array('controller' => 'events', 'event-id' => $eventId));
I don't think it's possible to have multiple subomains match in a single hostname route. So here's what you have to do:
Note: make sure the names of your routes are unique (note the
$i
being concatenated to make them unique). I forgot about that first time through and couldn't figure out why it wasn't working.You can't one route for non-linear mapping with more then two choices, so you'll have to use more then one ;) Without knowing the targets of each domain it's hard to give any examples. Assuming
example.com
andwww.example.com
are eaqual and are both the default route andstage
anddev
are both mapped to their respecitve module (andandreaw
andjoe
as parameters) (and added to the router of course):This will map the following (
:module/:controller/:action
):stage.example.com
tostage/index/index
dev.example.com
todev/index/index
joe.example.com
todev/index/index/user/joe
www.example.com
todefault/index/index
In words: if the sudomain is
stage
and nothing else, go to thestage
module with default parameters. If thesubdomain
isdev
go to thedev
module with parameteruser
. Else use the default zend route.Be careful that hostname routers do match any path. So you probably should match the path behind it with another route and using the chain router.
For the stage route this could look like this:
That'd map
stage.example.com/5434
tostage/browse/index/revision/5434
.