Assistance in mapping or routing a subdomain with the Zend Framework Controller (mobile version of the site)

What I'm trying to do is use the subdomain for the special mobile version of my ZF application. Ideally, this would compare with a specific controller, as an example below, but at this point I am ready to try any method that works:

Ex. m.domain.com/action will be redirected to the "mobile" controller and any action is indicated.

I found a number of similar questions here and elsewhere on Google, but I feel like I'm missing something obvious, because no matter which route I set up, it is simply ignored. I suspect it has something to do with htaccess, but it may not be so.

Here is the route that I have in my boot file (but I tried several different patterns here). Right now I'm just trying to get it to show a simple index for simplicity:

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

And my htaccess has:

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

Now I have two methods, because I was so upset.

  • Create subdomain "m" inside my hosting account
  • The subdomain "application" does not exist on my web hosting account

For method 1, it simply goes into the general index.html file, which is located in domain.com/m/. Method 2 tells me that the page does not exist.

I really hope that there is something obvious here that I am missing. As I mentioned above, I am not picky about how this is done if I have a subdomain pointing to a specific controller. This will be a very simplified version of the site, so I don’t need to do anything complicated.

Thank you for your help.

+4
source share
2 answers

First of all, you need to configure a virtual host to handle multiple domains:

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

You can also do this by adding a new subdomain pointing to the root of your site using the parameters of your hosting panel.

Then you can create a chain of routes, as in your example, or independently manage the switch, for example. in the controller plugin:

 $host = strtolower($request->getServer('HTTP_HOST')); if ('m.' === substr($host, 0, 2) || 'www.m.' === substr($host, 0, 6)) { $themes->setTheme('m'); $userSession->theme = 'm'; ... 
+3
source

I use something similar, but instead of matching the subdomains to the controller, I use it for the module, I use the following route:

 $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)); 
+1
source

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


All Articles