Symfony Match Route with Multiple Hosts


I know it is possible to filter a route by host, like this:

irc_backend.report.stacking_issue: path: /reports/stacking-issues host: backend.domain.com defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }

Is it possible to alter this configuration to match multiple domains? For example:

irc_backend.report.stacking_issue: path: /reports/stacking-issues host: backend.domain.com|dev.backend.domain.com defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }

I'm trying to avoid setting up 2 routes for every page.


You can try placeholders in your hostname with requirements (i.e.. <a href="http://symfony.com/doc/current/components/routing/hostname_pattern.html" rel="nofollow">Symfony Documentation</a>)

irc_backend.report.stacking_issue: path: /reports/stacking-issues host: "{mydomaines}" defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index } requirements: mydomaines: backend.domain.com|dev.backend.domain.com


If you read the <a href="http://symfony.com/doc/current/components/routing/hostname_pattern.html" rel="nofollow">Symfony documentation</a>, you'd know that you need to use placeholders. For your code, it would be :

irc_backend.report.stacking_issue: path: /reports/stacking-issues host: "{subdomain}.domain.com" defaults: _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index subdomain: backend requirements: subdomain: backend|dev.backend

I hope it'll help you !


If you want your default subdomain to be the current one, you can use a parameter like this :

irc_backend.report.stacking_issue: path: /reports/stacking-issues host: "{subdomain}.domain.com" defaults: _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index subdomain: "%subdomain%" requirements: subdomain: backend|dev.backend

Then you will be able to define this parameter in an <a href="http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html" rel="nofollow">Event listener</a> with this line of code :

$container->setParameter("subdomain", $your_subdomain);

P-S : Don't forget to add the Service container to your listener's dependencies


  • Cannot read property 'title' of undefined in angular2 [duplicate]
  • How to draw an arc segment with different fill and stroke colors for each side?
  • How can I calculate number of hops to reach destination ( NS2 )?
  • Laravel 5.1 ajax url parameter is url
  • Formula to remove entire words that start with certain characters
  • DELETE statement issues within a trigger definition
  • inserting duplicate records with SQL
  • Alter Table doesn't work under MS Access 64 bit. Why?
  • How to specify a multi-column UNIQUE constraint in code-first Entity Framework fluent API
  • Gradle test fails with NullPointerException
  • HTML checkbox form and HTTP URL
  • How to make SASS put relative paths in its output
  • Classic ASP URL Rewriting
  • Returning the auto incrementing value after an insert using slick
  • Xaml, wpf image position and crop issue
  • using html data-attributes as css-variable (i.e. text-shadow)
  • Magento get URL before current
  • Is there some graphical way to create my own configuration file on SonarLint?
  • Get specific string
  • Spring Cloud Microservice Architecture Confusion
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Meteor helpers not available in Angular template
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • How can I send an e-mail from a vbs script
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Is there a amazon webstore API for customers?
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • Rearranging Cells in UITableView Bug & Saving Changes
  • XCode can't find symbols for a specific iOS library/framework project
  • Is there a mandatory requirement to switch app.yaml?
  • Proper way to use connect-multiparty with express.js?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • Linking SubReports Without LinkChild/LinkMaster
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?