This bundle enables make routes with domain part.
$ git submodule add git://github.com/megazoll/MegazollDomainedRoutingBundle.git vendor/bundles/Megazoll/DomainedRoutingBundle
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Megazoll' => __DIR__.'/../vendor/bundles',
// ...
));
<?php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Megazoll\DomainedRoutingBundle\MegazollDomainedRoutingBundle(),
// ...
);
}
# app/config/config.yml
megazoll_domained_routing:
base_domain: example.com
default_domain_pattern: www.example.com
services:
router.default: @megazoll_domained_routing.router
# If you want spread authentication for subdomains.
framework:
session:
domain: .example.com
# nginx
server {
listen 80;
server_name example.com *.example.com;
...
}
# Apache
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
...
</VirtualHost>
<?php
// src/Acme/YourBundle/Controller/DomainController.php
/**
* Fallback with parameter in url
*
* @Route("/domain/{subDomain}/")
* @Route("/", name = "domain_action", options = {"domain_pattern" = "{subDomain}.%base_domain%"})
*/
public function domainActionAction($subDomain)
{
...
}