Apache Zend Framework:从路由获取子域参数
UPD: 解决了的。问题是因为我们使用nginx作为前端。因此nginx不会将HTTP_主机传递给apacheApache Zend Framework:从路由获取子域参数,apache,zend-framework,mod-rewrite,nginx,Apache,Zend Framework,Mod Rewrite,Nginx,UPD: 解决了的。问题是因为我们使用nginx作为前端。因此nginx不会将HTTP_主机传递给apache 你好 在本地主机上正常运行时,在生产服务器上的基本控制器中获取子域参数时遇到问题。url中的其他参数,如控制器,按其应返回的操作 这将在生产时返回null: $agencyName = (string) $this->_getParam('agency'); 未对.htaccess进行任何更改: RewriteEngine On RewriteRule ^main - [L,
你好 在本地主机上正常运行时,在生产服务器上的基本控制器中获取子域参数时遇到问题。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>
是的,我确实定义了$config['siteUri'],我还尝试使用:agency.domain.com再次遇到同样的问题
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时它对我有效)。已解决。问题是因为我们使用nginx作为前端。因此nginx不会将HTTP_主机传递给apache。似乎我们需要检查您使用的路由。请创建一个答案,而不是回答答案中的问题。详细说明一下。我在使用它时也有同样的问题。我的路由器在本地主机上运行良好。这意味着问题不在它们身上,而是在apache端的某个地方。您是否在本地主机上使用子域对它们进行了测试?如果它在本地工作,但不能在线工作,那么可能是应用程序(即您的siteUri可能错误)或apache配置中的配置问题。顺便问一下,更改设置后是否重新启动了apache?
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));
}
}