Symfony2主机名路由
I'm using hostname routing dependent on subdomain.
What I want to do is have two separate routings. When I'm running off www.example.com, then it uses one routing file, and if any other subdomain such as subdomain1.example.com or subdomain2.examples (etc etc), then it runs off another routing file.
My routing is as follows (yml):
route_www:
resource: "@AcmeBundle/Resources/config/routing/www/routing.yml"
host: www.%base_host%
route_sites:
resource: "@AcmeBundle/Resources/config/routing/sites/routing.yml"
Now this works to a point. I am using FOSUserBundle and I have all these routes in the route_sites, but www.example.com/register for example is still viewable as www is still valid for route_sites. Is there anyway possibly using regex, to prevent subdomain www from using the route_sites route.
Hope someone can help
我正在使用依赖于子域的主机名路由。 p>
我想要做的是有两个单独的路线。 当我在www.example.com上运行时,它使用一个路由文件,如果有任何其他子域,例如subdomain1.example.com或subdomain2.examples(等等),那么它将运行另一个路由文件。 p>
我的路由如下(yml): p>
route_www:
resource:“@ AcmeBundle / Resources / config / routing / www / routing.yml“
host:www。%base_host%
route_sites:
resource:”@ AcmeBundle / Resources / config / routing / sites / routing.yml“
code> pre>
现在这很有用。 我正在使用FOSUserBundle,我在route_sites中拥有所有这些路由,但是例如www.example.com/register仍可查看,因为www仍然对route_sites有效。 无论如何可能使用正则表达式,以防止子域名www使用route_sites路由。 p>
希望有人可以提供帮助 p>
div>
see this http://symfony.com/doc/current/components/routing/hostname_pattern.html
use a placeholder, then you can use regex in the requirments
You can try to use webserver virtual hosts configuration and set ENV variable in it. Based on this env variable you can load different symfony 2 environment or even different app (but you can still easy reuse/share entity mapping files, codebase with symlinks). It can be helpfull if you don't want to load all bundles or share some parts of config/codes.