I need to create a route in a zend framework 2 project that helps me to create these url:
- http://username.test.com and .net
- http://www.test.com and .net
Code:
<?php
return array (
'router' => array (
'routes' => array (
'username' => array (
'type' => 'hostname',
'options' => array (
'route' => ':username.test.:tld',
'constraints' => array(
'username' => '[a-zA-Z][a-zA-Z0-9_-]*',
'tld' => '[com|net]*',
),
'defaults' => array (
'controller' => 'Application\Controller\Index',
'action' => 'show',
'tld' => 'com'
)
)
),
'home' => array (
'type' => 'hostname',
'options' => array (
'route' => 'www.test.:tld',
'constraints' => array(
'tld' => '[com|net]*',
),
'defaults' => array (
'controller' => 'Application\Controller\Index',
'action' => 'index',
'tld' => 'com'
)
)
),
)
),
In some case when I call the http://username.test.com url I need to redirect the user to the http://www.test.com by the url helper.
update:
For instance the zfUser has a specific routes to serve the user:
- /user
- /user/register
- /user/logout
When I execute this code when the application starts from the http://username.test.com
<a href="<?php echo $this->url('zfcuser') ?>" title="Profilo"><i class="fa fa-user"></i><?php echo $this->translate('Your Profile') ?></a>
It creates a links like these:
- http://username.test.com/user
- http://username.test.com/user/register
- http://username.test.com/user/logout
and I would like this:
How I can do it?