0

I added a reseller subdomain on my myhost.com (reseller.myhost.com) and I use it for routing to my Reseller module. Read this question I posted before here: click here

My Reseller route config looks this:

'router' => array(
    'routes' => array(
        'Reseller' => array(
            'type'    => 'Hostname',
            'options' => array(
                'route'    => 'reseller.myhost.com',
                'constraints' => array(

                ),
                'defaults' => array(
                    'controller' => 'Reseller\Controller\Reseller',
                    'action'     => 'index'
                )
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'home' => array(
                    'type' => 'Zend\Mvc\Router\Http\Literal',
                    'options' => array(
                        'route'    => '/',
                        'defaults' => array(
                            '__NAMESPACE__' => 'Reseller\Controller',
                            'controller'    => 'Reseller',
                            'action'        => 'index',
                         ),
                    ),
                ),

            )
        )
    )
)

My createdAd route matches on reseller.myhost.com/createdAd but I expect routes from other modules not work on this reseller subdomain.

and here is my advertise route configuration

    'router' => array(
         'routes' => array(
             'locate' => array(
                 'type'    => 'segment',
                 'options' => array(
                     'route'    => '/locate[/:cityName][/:CityId][/:CategoryId][/:categoryName]',
                     'constraints' => array(

                     ),
                     'defaults' => array(
                         'controller' => 'Advertise\Controller\Advertise',
                         'action'     => 'index',
                     ),
                 ),
             ),


             'createAd' => array(
                 'type'    => 'segment',
                 'options' => array(
                     'route'    => '/createAd[/:subCategoryId]',
                     'constraints' => array(

                     ),
                     'defaults' => array(
                         'controller' => 'Advertise\Controller\Advertise',
                         'action'     => 'createAd',
                     ),
                 ),
             ),




         ),
     ),


 ));

be notice that i want to advertise module work without subdomain and work normally and only reseller module work with subdomain

Why does this occur?

Community
  • 1
  • 1
babak faghihian
  • 1,169
  • 2
  • 13
  • 24
  • I don't understand what is the problem. Can you please add some more details. What is expected? What is happening? What does the route config look like in the "other modules" that you mention. – Wilt Jun 30 '15 at 12:10
  • @Wilt my firend i excpet to route of reseller.myhost.com/createAdvertise dosent work beacuse createAdvertise route defined in advertise controller not in ResellerController – babak faghihian Jun 30 '15 at 19:15

2 Answers2

0

I understand from your question: you expect the createAd route not to work on the subdomain. So reseller.myhost.com/createdAd should not match instead you want a to match on the route without subdomain myhost.com/createdAd.

I would suggest that you should create a separate route definition for the Advertise module.

Your route config in Advertise module (module/Advertise/config/module.config.php)

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Advertise\Controller\Advertise',
                    'action'     => 'index'
                )
            ),
        )
        'createAd' => array(
            'type' => 'Literal',
            'options' => array(
                'route'    => '/createAd',
                'defaults' => array(
                    'controller' => 'Advertise\Controller\Advertise',
                    'action'     => 'createAd',
                )
            )
        )
    )
)

Your route config in Reseller module (module/Reseller/config/module.config.php)

'router' => array(
    'routes' => array(
        'Reseller' => array(
            'type'    => 'Hostname',
            'options' => array(
                'route'    => ':reseller.myhost.com',
            ),
            'may_terminate' => false,
            'child_routes' => array(
                'home' => array(
                    'type' => 'Literal',
                    'options' => array(
                        'route'    => '/',
                        'defaults' => array(
                            'controller' => 'Reseller\Controller\Reseller',
                            'action'     => 'index'
                        )
                    )
                )
            )
        )
    )
),

You can distinguish matches because of the subdomain.

The routes home and createAdd match the Advertise module without subdomain.

The route reseller.home matches the index in Reseller module within subdomain reseller.myhost.com.

Check for more details also the Hostname routing example here in the ZF2 documentation

Wilt
  • 41,477
  • 12
  • 152
  • 203
0

You should have a "root" hostname for all your standard routes not on the subdomain route. Eg:

'router' => array(
    'routes' => array(
        'myhost' => array(
            'type'    => 'Hostname',
            'options' => array(
                'route'    => 'myhost.com',
            ),
        ),
    ),
),

Now you can add your 'createAd' route (and other routes) as a child route of the 'myhost' route. Eg:

'router' => [
    'routes' => [
        'myhost' => [
            'child_routes' => [
                'createAd' => array(
                     'type'    => 'segment',
                     'options' => array(
                         'route'    => '/createAd[/:subCategoryId]',
                         'constraints' => array(

                         ),
                         'defaults' => array(
                             'controller' => 'Advertise\Controller\Advertise',
                             'action'     => 'createAd',
                         ),
                     ),
                 ),
             ],
         ],
     ],
],
briangallagher
  • 539
  • 4
  • 15