2011-03-03 24 views
4

UPD: 已解决。问题是因为我们使用nginx作为前端。所以nginx不会将HTTP_HOST传递给apache。Zend Framework:从路由获取子域参数


你好!

我在生产服务器上的本地控制器上获取子域参数时出现问题,而本地主机没问题。来自URL的其他参数,如控制器,操作返回,因为他们应该。

返回null生产:

$agencyName = (string) $this->_getParam('agency'); 

作出的.htaccess没有变化:

RewriteEngine On 
RewriteRule ^main - [L,NC] 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

这是我的虚拟主机设置:

<VirtualHost *:8080> 
     ServerName agencies.domain.com 
     ServerAlias *.agencies.domain.com 

     ErrorLog /var/log/apache2/agencies.domain_errors.log 

     DocumentRoot /var/www/agencies.domain.com/public/ 

     <Directory "/var/www/agencies.domain.com/public"> 
       Options -Indexes FollowSymLinks Includes 
       DirectoryIndex index.shtml index.php 
       AllowOverride All 
       # Controls who can get stuff from this server. 
       Order allow,deny 
       Allow from all 
     </Directory> 
</VirtualHost> 

有谁知道为什么一切发生的时候?

UPD:在引导

public function run() 
    { 
     $frontController = Zend_Controller_Front::getInstance(); 
     $router = $frontController->getRouter(); 

     $plainPathRoute = new Zend_Controller_Router_Route(
         ':module/:controller/:action/*', 
         array(
          'module' => 'default', 
          'controller' => 'index', 
          'action' => 'index', 
         ) 
     ); 

     $config = $this->getOptions(); 

     $hostnameRoute = new Zend_Controller_Router_Route_Hostname(
         ':agency.' . $config['siteUri'], 
         NULL, 
         array(
          'agency' => '([a-z0-9]+)' 
         ) 
     ); 

     $router->addRoute('subdomain', $hostnameRoute->chain($plainPathRoute)); 

     parent::run(); 
    } 

路由器,是的,我有$配置[ 'siteUri']定义的,我也尝试使用:agency.domain.com再次得到了同样的问题

+0

好像我们需要检查您正在使用的路线。 – 2011-03-03 14:17:06

+0

请创建答案,而不是回答答案中的问题。详细一点。 – markus 2011-03-04 08:34:54

回答

1

已解决。问题是因为我们使用nginx作为前端。所以nginx不会将HTTP_HOST传递给apache。

4

使用以下命令:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{ 
    protected function _initRoute() 
    { 
     $this->bootstrap('FrontController'); 
     $router = $this->getResource('FrontController')->getRouter(); 
     $router->removeDefaultRoutes(); 
     $plainPathRoute = new Zend_Controller_Router_Route(
         ':module/:controller/:action/*', 
         array(
          'module' => 'default', 
          'controller' => 'index', 
          'action' => 'index', 
         ) 
     ); 
     $router->addRoute('default', $plainPathRoute); 
     $config = $this->getOptions(); 
     $hostnameRoute = new Zend_Controller_Router_Route_Hostname(
         ':agency.' . $config['siteUri'], 
         NULL, 
         array(
          'agency' => '([a-z0-9]+)' 
         ) 
     ); 
     $router->addRoute('subdomain', $hostnameRoute->chain($plainPathRoute)); 
    } 
} 

如果提供有效的子域(即。只包含字符a-z0-9),它会在代理中传递,如果不是,那么代理不会被设置。 (至少它适用于我使用ZF 1.11.3:p)。

+0

+1我试了一下,它的工作:) – tawfekov 2011-03-03 15:49:30

+0

我有使用它的同样的问题。我的路由器在本地主机上正常工作。这意味着问题不在他们身上,而是放在Apache的某个地方。 – Fenec 2011-03-03 15:56:38

+0

你真的用你本地主机上的子域来测试它们吗?如果它在本地工作并且不能在线工作,那么它可能是应用程序中的配置问题(即,您的站点URI可能是错误的)或者在apache配置中。顺便说一句,你改变设置后重新启动Apache? – wimvds 2011-03-03 21:17:08