Zend framework 帮助将子域映射或路由到Zend Framework Controller(站点的移动版本)

Zend framework 帮助将子域映射或路由到Zend Framework Controller(站点的移动版本),zend-framework,routing,controller,subdomain,Zend Framework,Routing,Controller,Subdomain,我试图做的是为我的ZF应用程序的特殊移动版本使用子域。理想情况下,它会映射到一个特定的控制器,如下面的示例,但在这一点上,我愿意尝试任何有效的方法: Ex.m.domain.com/action将路由到“移动”控制器和指定的任何操作 我在谷歌上发现了很多类似的问题,但我觉得我错过了一些明显的东西,因为无论我设置了什么路线,它都被忽略了。我怀疑这与htaccess有关,但可能是错误的 这是我目前在引导文件中的路径(但我在这里尝试了许多不同的模式)。现在我只是想让它显示简单的索引: $hostRou

我试图做的是为我的ZF应用程序的特殊移动版本使用子域。理想情况下,它会映射到一个特定的控制器,如下面的示例,但在这一点上,我愿意尝试任何有效的方法:

Ex.m.domain.com/action将路由到“移动”控制器和指定的任何操作

我在谷歌上发现了很多类似的问题,但我觉得我错过了一些明显的东西,因为无论我设置了什么路线,它都被忽略了。我怀疑这与htaccess有关,但可能是错误的

这是我目前在引导文件中的路径(但我在这里尝试了许多不同的模式)。现在我只是想让它显示简单的索引:

$hostRoute = new Zend_Controller_Router_Route_Hostname(':subdomain.domain.com', 
        array(
            'controller' => 'index',
            'action' => 'index'
            )
    );
$plainPathRoute = new Zend_Controller_Router_Route(':controller/:action/*',     
    array('controller' => 'index', 'action' => 'index'));
$controller->getRouter()->addRoute('mobile', $hostRoute->chain($plainPathRoute));
我的htaccess有:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在我在这里尝试了两种方法,因为我很沮丧

  • 在我的托管帐户内创建子域“m”
  • 我的web托管帐户上不存在子域“app”
  • 对于方法1,它只转到domain.com/m/中的generic index.html文件。方法2告诉我页面不存在

    我真的希望这里有一些明显的东西我错过了。就像我上面提到的,我并不挑剔如何执行它,只要我有一个子域指向一个特定的控制器。这将是一个非常简化的网站版本,所以我真的不需要做任何复杂的事情


    谢谢您的帮助。

    我使用了类似的方法,但我使用的不是到控制器的子域映射,而是用于模块,我使用以下路径:

    $hostnameRoute = new Zend_Controller_Router_Route_Hostname(
            ':module.domain.com',
            array(
                'module' => 'default'
            )
        );
        $normalRoute = new Zend_Controller_Router_Route(
            ':controller/:action/*',
            array(
                'controller' => 'index',
                'action' => 'index'
            )
        );
        $router->addRoute('default', $hostnameRoute->chain($normalRoute));
    

    首先,您需要配置虚拟主机以处理多个域:

    <VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        ServerAlias m.example.com
        ServerAlias www.m.example.com
        ...
    

    谢谢你,克里斯。您的htaccess是如何工作的?我怀疑我的请求在某种程度上绕过了将请求转发到index.php的过程,因此在我使用的ini文件中从未拾取路由,就像这样mysubroute.route=“subdomain.domain.com”mysubroute.type=“Zend\u Controller\u Router\u route\u Hostname”mysubroute.defaults.Controller=“mycontroller”mysubroute.defaults.action=“index”mysubroute.chains.normal.route=“:action/*”mysubroute.chains.normal.type=“Zend\u Controller\u Router\u route”mysubroute.defaults.Controller=“mycontroller”因此subdomain.domain.com和subdomain.domain.com/action等工作正常!
    $host = strtolower($request->getServer('HTTP_HOST'));
    if ('m.' === substr($host, 0, 2) || 'www.m.' === substr($host, 0, 6)) {
        $themes->setTheme('m');
        $userSession->theme = 'm';
        ...