0

I have problem with 'dynamic subdomains' on zend_router_hostname, i have code like(i don't have subdomains like that but whant use subdomain as route parametr):

protected function _initRoutes() {
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        $config = $this->getOptions();
        Zend_Registry::set("config", $config);
        $routerHost = new Zend_Controller_Router_Hostname(':language.mysite.local',
                        array('controller' => 'index',
                            'action' => 'index',
                            'language'=>'pl')
);
        $router->addDefaultRoutes();
        $routes = $router->getRoutes();
        foreach ($routes as $key => $routeEntry) {
            $router->addRoute($key, $routeHost->chain($routeEntry));
        }
    }

But when I try do call eg.: pl.mysite.local i get Server not found error. My /etc/hosts file is:

127.0.0.1       localhost
127.0.2.1       mysite.local
127.0.3.1       mysite.dev
127.0.4.1       mysite.production

And my vhost config is:

VirtualHost *:80>
   DocumentRoot "/var/www/mysite/public"
   ServerName mysite.local
   ServerAlias *.mysite.local
   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development
   <Directory "/var/www/mysite/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>

</VirtualHost>

I tried to use dnsmasq with entry like:

address=/local/127.0.0.1

But problem still occurs, i dont know how to resolve this situation, any clue what i'm doing wrong?

Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
Axxxon
  • 703
  • 2
  • 11
  • 27
  • Don't make your application complex. Route subdomains within the server configuration first, then do standard routing in Zend Framework. Your application will say thank you to you. – hakre Aug 09 '12 at 12:12

1 Answers1

2

Adding wildcards to /etc/hosts is not possible but, also required in our case. However, this is how to go about it:

Install dnsmasq

then,

cp /usr/share/doc/dnsmasq-base/examples/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

then, edit your /usr/local/etc/dnsmasq.conf and add:

address=/mysite.local/127.0.0.1
listen-address=127.0.0.1

Start DNSMASQ:

~$ sudo ./usr/local/sbin/dnsmasq

Further, instead of using Zend_Controller_Router_Hostname use Zend_Controller_Router_Route_Hostname

Go through the document and you should be OK!

$toRoute = new Zend_Controller_Router_Route_Hostname(
    ':language.mysite.local',
    array(
        'controller' => 'index',
        'action' => 'index',
        'language' => 'pl')
    ) );

PS: Don't forget to mention nameserver as 127.0.0.1 in /etc/resolv.conf . At times, restarting system helps!

Enjoy coding! :)

Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
  • I get it, the problem is that whatever you define in routers is checked as a 'suffix' to your base domain. example: :xyz/yes will be example.com/xyz/{value}/yes and since you have used dot, it should give you an error too! anyways, let me check. However, host file is correctly set now, wait for router script. – Keval Domadia Aug 09 '12 at 08:07
  • @Axxxon I have edited the post. Check for the correct function to use (link provided). Also, tick it correct, if it works, if it doesn't then, let me know what came up! – Keval Domadia Aug 09 '12 at 08:12
  • i have changed it as You suggested @KarmicDice, now when trying to get to mysite.local i got redirect to www.mysite.local but problem with subdomains still occurs. – Axxxon Aug 09 '12 at 11:42
  • By any chance is your htaccess causing conflict? Redirected to www *eh?* that is strange! You added the route? I presume you did! Ok, what about your controller, it is fetching getParam(pl), isnt it? – Keval Domadia Aug 09 '12 at 11:55
  • @Axxxon Whew! Finally got the solution after long coffee sips :D /etc/hosts wildcards != work. So, put your /etc/hosts to as it was. and Follow the solution, as shown above. If still it doesn't, come back and mention it. :) – Keval Domadia Aug 09 '12 at 12:13
  • i edited /etc/hosts like You suggested @KarmicDice, changed dnsmasq config, used code in my Bootstrap.php as mentioned, and checked /etc/resolv.conf but now dynamic-subdomains don't work and while calling mysite.local i get No route matched the request error – Axxxon Aug 09 '12 at 13:33
  • is it normal that after adding 127.0.0.1 pl.mysite.local to /etc/hosts i got server response but problem with routes still occurs? – Axxxon Aug 09 '12 at 13:54
  • adding subdomain.hostname on /etc/hosts is not the solution. You need to configure DNS wildcard which we do using dnsmasq. I will get back on this on Monday :) Enjoy ur weekend! – Keval Domadia Aug 10 '12 at 09:59