Php 如何将到www.example.com/admin的请求重定向到Zend中的不同模块

Php 如何将到www.example.com/admin的请求重定向到Zend中的不同模块,php,zend-framework,routes,zend-framework-modules,Php,Zend Framework,Routes,Zend Framework Modules,我在重定向应用程序中的请求时遇到问题 我的规则: employer.domain.com-应指向雇主的页面-使用默认模块 employer.domain.com/panel/-应指向特定雇主的管理页面-使用仪表板模块 www.domain.com-应指向聚合所有雇主的页面-使用默认模块 我已经测试了很多不同的路线,但是当一条路线起作用时,另一条路线就会被破坏。它通常只对根路径有效,但当我添加对某个控制器和操作的调用时,它会崩溃。也许我应该编写自定义控制器插件?你觉得怎么样 这是我当前的配置。

我在重定向应用程序中的请求时遇到问题

我的规则:

  • employer.domain.com-应指向雇主的页面-使用默认模块
  • employer.domain.com/panel/-应指向特定雇主的管理页面-使用仪表板模块
  • www.domain.com-应指向聚合所有雇主的页面-使用默认模块
我已经测试了很多不同的路线,但是当一条路线起作用时,另一条路线就会被破坏。它通常只对根路径有效,但当我添加对某个控制器和操作的调用时,它会崩溃。也许我应该编写自定义控制器插件?你觉得怎么样

这是我当前的配置。这是一团乱,但也许会有助于抓住一些愚蠢的错误

// employer.domain.com/panel
$pathRoute_panel = new Zend_Controller_Router_Route(
    ':panel/:controller/:action/:id/',
    array(
        'panel' => '',
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index',
        'id' => '',
    ),
    array(
        'panel' => 'panel'
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));


// employer.domain.com - main employer page
$pathRoute_panel = new Zend_Controller_Router_Route(
    '',
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));


// domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'index',
    ),
    $dispatcher,
    $request
);

$route = new Zend_Controller_Router_Route_Hostname($config['host']);
$router->addRoute('default', $route->chain($pathRoute));

// www.domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'index',
    ),
    $dispatcher,
    $request
);

$route = new Zend_Controller_Router_Route_Hostname('www.'.$config['host']);
$router->addRoute('default_www', $route->chain($pathRoute));
编辑:这是我的解决方案:

// employer.domain.com
$pathRoute_panel = new Zend_Controller_Router_Route_Module(
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));

// employer.domain.com/panel/
$pathRoute_panel = new Zend_Controller_Router_Route(
    'panel/:controller/:action/:id/',
    array(
        'panel' => 'panel',
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index',
        'id' => '',
    )
);

$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    ':employer.'.$config['host'],
    null,
    array(
        'employer' => '([a-z0-9]+)',
    )
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));

注释在代码中。您可以使用通配符(*)进一步匹配任何内容!没有必要使用
默认路径\u www
路径-这只是默认行为(默认路径现在将匹配除雇主之外的每个子域,因为它与
子域路径相匹配)。

对于您发布的路径,哪些路径按预期工作,哪些不按预期工作?你能给出一个例子URL,当你添加控制器和操作时,它不起作用。工作:employer.domain.com,employer.domain.com/panel/,domain.com Not work:employer.domain.com/some-controller/some-action我正在尝试你的解决方案。另外,我知道不止一条路线可以用链子拴住,但我太害怕了,不敢尝试;)恐怕这对我不起作用。我为我的应用程序重写了您的解决方案,但它无法重定向任何URL。下面我发布了我的解决方案,看起来很有效。@MaxBarnas:由于您没有强制执行特定的子域,我想它适用于任何子域。
// Enforce Subdomain usage
// Will match employer.domain.com/*
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
    'employer.'.$config['host'] . '/*'
);


// Will match /panel/{id, required}/{controller, optional}/{action, optional}/{further parameters, optional}
$pathRoute_panel = new Zend_Controller_Router_Route(
    'panel/:id/:controller/:action/*',
    array(
        'module' => 'dashboard',
        'controller' => 'index',
        'action' => 'index'
    ),
    array(
        'id' => '\d+'
    )
);

// employer.domain.com - main employer page
// will match everything not matched before!
$pathRoute_page = new Zend_Controller_Router_Route(
    '*',
    array(
        'module' => 'default',
        'controller' => 'vcard',
        'action' => 'index'
    )
);

// You can add several routes to one chain ;) The order does matter.
$subDomainRoute->chain($pathRoute_page);
$subDomainRoute->chain($pathRoute_panel);
$router->addRoute($subDomainRoute);