UPD:
解决了.问题是因为我们使用Nginx作为前端.所以Nginx没有将HTTP_HOST传递给apache.
嗨,您好!
我在生产服务器上的基本控制器中获取子域参数时遇到问题,而在本地主机上则没问题.来自url的其他参数,如controller,action应该返回.
这在生产时返回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]
这是我的vhost设置:
<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:
Bootstrap中的路由器
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();
}
是的,我确实定义了$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).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。