Route a domain by Zend-Router-Route-Hostname in Zend Framework


Zend Framework logo.
Image via Wikipedia

In my company most of our projects we have been using custom-zend framework and I love their routing concepts. It gives you various options of handling many different routes to get the data based on your needs – just amazing.

Let me get straight with the topic. With Zend Framework, it is easy to route your URL in a nice way without having an head-ache of working with .HTACCESS file. Thanks a bunch.

Most of us know how to route an URL with routes.ini, for example:

routes.contact.route                           = “contact-us”
routes.contact.defaults.module      = “contact”
routes.contact.defaults.controller = “contact”
routes.contact.defaults.action        = “index”
– this will route a URL http://example.com/contact-us into “contact” module >> “ContactController.php” controller >> “indexAction()”  action.

What’s the big deal? We know this, yes I agree, have you tried routing a domain?..😉 Most of us may not, definitely I have not it does not stop there yet, Zend Framework also gives you an option to route an URL based on host/domain name and that is cool!.

Yes it is, you can route a domain (hostname) too, see the example:

routes.contact.type                = Zend_Controller_Router_Route_Hostname
routes.contact.route               = “contact.example.com”
routes.contact.defaults.module     = “contact”
routes.contact.defaults.controller = “contact”
routes.contact.defaults.action     = “index”
 
– this will route a domain http://contact.example.com/ to “Contact” module >> “Contact” controller >> “Index” action.
– to get this working you have to specify the type of router in the type variable “Zend_Controller_Router_Route_Hostname“, by default zend framework will assign “Zend_Controller_Router_Route” to the type.
– see the list of other route-type given by zend framework router.
Happy Coding!

Related Articles

Route a domain by Zend-Router-Route-Hostname in Zend Framework

One thought on “Route a domain by Zend-Router-Route-Hostname in Zend Framework

  1. Elena says:

    It’s difficult to find knowledgeable people in this particular topic, however, you sound like you know what you’re talking about! Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s