Adding sub domain based routes in Zend framework

前端 未结 2 869
情书的邮戳
情书的邮戳 2020-12-08 23:49

I am newbie to Zend framework, I am using .ini file to add routes in my application.

I have 2 routes for different modules which

resources.router.r         


        
相关标签:
2条回答
  • 2020-12-09 00:04

    Hi after much browsing in the web I came up with this solution for my problem

    resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname"
    resources.router.routes.www.route = ":module.findchennai.com"
    resources.router.routes.www.defaults.module = "www"
    resources.router.routes.www.chains.index.type = "Zend_Controller_Router_Route"
    resources.router.routes.www.chains.index.route = ":controller/:action/*"
    resources.router.routes.www.chains.index.defaults.controller = "index"
    resources.router.routes.www.chains.index.defaults.action = "index"
    

    The above code maps the module with sub domain

    resources.router.routes.news.type = "Zend_Controller_Router_Route_Hostname"
    resources.router.routes.news.route = "news.findchennai.com"
    resources.router.routes.news.defaults.module = "news"
    
    resources.router.routes.edu.type = "Zend_Controller_Router_Route_Hostname"
    resources.router.routes.edu.route = "education.findchennai.com"
    resources.router.routes.edu.defaults.module = "education"
    
    resources.router.routes.edu.chains.list.type = "Zend_Controller_Router_Route"
    resources.router.routes.edu.chains.list.route = ":categ/:page"
    resources.router.routes.edu.chains.list.defaults.controller = "index"
    resources.router.routes.edu.chains.list.defaults.action = "category"
    resources.router.routes.edu.chains.list.defaults.page = 1
    
    resources.router.routes.news.chains.list.type = "Zend_Controller_Router_Route"
    resources.router.routes.news.chains.list.route = ":categ/:page"
    resources.router.routes.news.chains.list.defaults.controller = "index"
    resources.router.routes.news.chains.list.defaults.action = "category"
    resources.router.routes.news.chains.list.defaults.page = 1
    

    This solves the problem I faced and now could map correctly to the following urls

    http://news.mysite.com/27-08-09/sample.html
    http://education.mysite.com/27-08-09/sample.html
    

    Still if some one knows how to optimise the above code further, Please let me know.

    0 讨论(0)
  • 2020-12-09 00:12

    Do both subdomains call into the same index.php?

    If they don't only set the route based on the appropriate sub domain instead of setting both routes in both sub domains.

    If they do either read from the $_SERVER['HTTP_HOST'] variable and set the correct route based on the subdomain or set an environment variable in your .htaccess file so you can tell which subdomain you are in.

    0 讨论(0)
提交回复
热议问题