Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:58:47+00:00 2026-06-13T17:58:47+00:00

After searching a long time with no success. before I give up, I would

  • 0

After searching a long time with no success.
before I give up, I would like to ask:

Is there a way to route a subdomain to a module in Zend Framework 2? like:

Subdomain => Module
api.site.com => api
dev.site.com => dev
admin.site.com => admin
site.com => public
…

I tried doing it like this but I can’t get access to controllers other than the default (Index).

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Hostname',
            'options' => array(
                'route' => 'site.com',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            )
        )
    ),
),

Thank you for taking the time to help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:58:48+00:00Added an answer on June 13, 2026 at 5:58 pm

    Zend Framework 2 doesn’t have a notion of routing to modules; all routing mappings are between a URI pattern (for HTTP routes) and a specific controller class. That said, Zend\Mvc provides an event listener (Zend\Mvc\ModuleRouteListener) which allows you to define a URI pattern that maps to multiple controllers based on a given pattern, and so emulates “module routing”. To define such a route, you would place this as your routing configuration:

    'router' => array(
        'routes' => array(
             // This defines the hostname route which forms the base
             // of each "child" route
            'home' => array(
                'type' => 'Hostname',
                'options' => array(
                    'route' => 'site.com',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This Segment route captures the requested controller
                    // and action from the URI and, through ModuleRouteListener,
                    // selects the correct controller class to use
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                                'controller' => 'Index',
                                'action'     => 'index',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    

    (Click here to see an example of this @ ZendSkeletonApplication)

    This is only half of the equation, though. You must also register every controller class in your module using a specific naming format. This is also done through the same configuration file:

    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController'
        ),
    ),
    

    The array key is the alias ModuleRouteListener will use to find the right controller, and it must be in the following format:

    <Namespace>\<Controller>\<Action>
    

    The value assigned to this array key is the fully-qualified name of the controller class.

    (Click here to see an example of this @ ZendSkeletonApplication)

    NOTE: IF you aren’t using ZendSkeletonApplication, or have removed it’s default Application module, you will need to register the ModuleRouteListener in one of your own modules. Click here to see an example of how ZendSkeletonApplication registers this listener

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After long time of searching I have to give up and ask. Is it
After searching for a long time I've decided to just ask it here, since
After a long time searching for the best way to en/decrypt data between PHP
After searching for a long time for a simple way of changing the text
After searching a long time for a performance bug, I read about denormal floating
After a long time searching and trying I'm asking now for help: My situation:
After searching long time Im unable to find any information on how to best
After long time of searching the best upload technique I've decided to go with
This is a stupidly easy question, however after searching for a long time I
I tried to add JOGL to my project, and after a long time searching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.