Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:45+00:00 2026-06-07T04:06:45+00:00

I have some fairly complex routing rules, that are only achievable with custom code,

  • 0

I have some fairly complex routing rules, that are only achievable with custom code, and not with the default router.

The router has also to take into account the domain name.

Is it possible (and how) to define my own Router class, that would have a method accepting a Request and returning the bundle/controller name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:06:46+00:00Added an answer on June 7, 2026 at 4:06 am

    To achieve what you’re asking, you don’t need to completely redefine the router

    You can simply write your own class that implements UrlMatcherInterface. If you want to be able to generate URLs that match your scheme as well, you’ll have to create another class which overrides UrlGeneratorInterface as well.

    In order to take into account the domain name, you’ll need to use RequestContext, which is passed to their constructors (it’s not well documented, but check Router::get{Matcher,Generator} for the details).

    Once your classes are prepared, you can inject them into the router simply by overriding the parameters “router.options.generator_class” and “router.options.matcher_class” in your bundle.


    However, it may not be the best approach for what you want – overriding parts of the router like that requires a lot of care to preserve all of the caching.

    You might want to consider using Symfony2’s normal router, but handing it different route files depending on what the request’s domain is. This can be done easily if you configure your web server to set a variable or execute a different front controller depending on the domain name.

    Using that information, you can then load a different ‘environment’ per-request, with the only difference between the different environments being that they use different routing files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly complex object which has some C# code written to render
I'm writing some fairly complex C# code. I'm finding that my code is throwing
I have some fairly complex requirements for a SOLR search that I need to
I have some fairly old code that runs just fine in Excel versions before
I have some fairly complex libraries that interconnect with each other to do some
I have some fairly complex java programs with lots of if/else statements where various
I have a fairly complex model needing to be validated, the problem is that
I have a fairly complex relationship that I am trying to make work with
I have a fairly complex function f(x) that I want to optimize and I
I've got a fairly complex classic asp page that for some users doesn't render

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.