Zend Framework: get subdomain parameter from route

UPD: Solvable. The problem was that we are using nginx as an interface. Therefore nginx does not pass HTTP_HOST to apache.


Hello!

I had a problem getting the subdomain parameter in my base controller on the production server, while on localhost this is normal. other parameters from url-like controller, the action is returned, as it should be.

this returns null on creation:

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

no changes to .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] 

and here are my vhost settings:

 <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> 

Does anyone know why this is happening?

UPD:

routers in 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(); } 

and yes, I have $ config ['siteUri'] and I also tried using: agency.domain.com getting the same problem again

+4
source share
2 answers

solved. The problem was that we are using nginx as an interface. Therefore nginx does not pass HTTP_HOST to apache.

+1
source

Use the following:

 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)); } } 

If you provide a valid subdomain (i.e. consisting of a-z0-9 characters only), it will be transferred to the agency; if not, the agency will not be established. (At least it works for me using ZF 1.11.3: p).

+4
source

Source: https://habr.com/ru/post/1342121/


All Articles