I have my app setup to use 3 subdomains, I also have 2 domains that point to the same app, giving me this set of FQDNs
admin.domain1.com, admin.domain2.com
www.domain1.com, www.domain2.com
kiosk.domain1.com, kiosk.domain2.com
In routing.yml I can set up the host / resource keys to point those domains at the relevant bundle, but I can only do it for one of the domains at a time.
incompass_admin:
host: admin.domain1.com
resource: "#IncompassAdminBundle/Resources/config/routes.yml"
incompass_web:
host: www.domain1.com
resource: "#IncompassWebBundle/Resources/config/routes.yml"
incompass_kiosk:
host: kiosk.domain1.com
resource: "#IncompassKioskBundle/Resources/config/routes.yml"
When I try something like this
incompass_kiosk_1:
host: kiosk.domain1.com
resource: "#IncompassKioskBundle/Resources/config/routes.yml"
incompass_kiosk_2:
host: kiosk.domain2.com
resource: "#IncompassKioskBundle/Resources/config/routes.yml"
The second domain is the only one that is recognised, kiosk.domain1.com throws an exception: No route found for "GET /"
Is there a way to either set the domain as a wildcard in routing.yml, or to point 2 different routes to the same resource?
edit: I've also tried to have
IncompassKioskBundle/Resources/config/routes_1.yml
IncompassKioskBundle/Resources/config/routes_2.yml
and
IncompassKioskBundle/Resources/config/routes.yml
IncompassRoutingBundle/Resources/config/kiosk_routes.yml
where the names of the routes in the 2 files are different e.g.
// routes.yml
domain_one_kiosk_scanning:
type: annotation
prefix: /
resource: Incompass\KioskBundle\Controller\ScanningController
domain_one_kiosk_printing:
type: annotation
prefix: /print
resource: Incompass\KioskBundle\Controller\PrintingController
// kiosk_routes.yml
domain_two_kiosk_scanning:
type: annotation
prefix: /
resource: Incompass\KioskBundle\Controller\ScanningController
domain_two_kiosk_printing:
type: annotation
prefix: /print
resource: Incompass\KioskBundle\Controller\PrintingController
That did not work.
You can use placeholders in routes, so try something like this:
incompass_kiosk:
host: "kiosk.{domain}.com"
resource: "#IncompassKioskBundle/Resources/config/routes.yml"
requirements:
domain: domain1|domain2
defaults: { domain: domain1 }
You could alternatively handle this in your .htaccess or virtual host configuration.
Related
I'm using annotations in my project but to redirects using routes.yaml
If exists routing (ex. /home name="home"} that redirect not working:
home-301:
path: /home
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-home
permanent: true
I found solution but I thing it is no good practice:
cleared: config/routes/annotations.yaml
and appended to the end of the file config/routes.yaml:
controllers:
resource: ../../src/Controller/
type: annotation
how to do it right?
My solution:
all redirects put in: config/routers/redirects.yaml
and config/routes.yaml:
redirects:
resource: routes/redirects.yaml
annotations:
resource: routes/annotations.yaml
I need to add a requirement for my api route (only allow 3 mgn , user and adm) but i get the error:
MissingMandatoryParametersException
Some mandatory parameters are missing ("role") to generate a URL for route "api_doc".
here is my route:
api_platform:
resource: .
type: api_platform
prefix: /{role}/api
requirements:
role: "mng|adm|user"
should i install or set something?, thank you
already find a solution
if some person need it
api_platform:
resource: .
type: api_platform
prefix: /{app}/api
defaults:
app: take|mngr|drvr
requirements:
app: take|mngr|drvr
thank you
I have two routes in two separated bundles: bundleA_route, bundleB_route. In my /app/config/routing.yml I load them as resources like:
bundle_a_routing:
resource: "#SomeABundle/Resources/config/routing.yml"
prefix: /
bundle_b_routing:
resource: "#SomeBBundle/Resources/config/routing.yml"
prefix: /
In most cases this sequence is required, first of all try to match on routes in bundle_a_routing, and then try to match on routes in bundle_b_routing, but in only one case I want to make an exception, I want a single route defined in bundle_b_routing to be matched before the more "concessive" route defined in bundle_a_routing:
route_in_bundle_a:
path: /admin/{path}
defaults: { _controller: SomeABundle:SomeCtrl:someAction }
methods: [GET]
requirements:
path: ^(.*)$
route_in_bundle_b:
path: /admin/download/{formId}/{fileName}
defaults: { _controller: SomeBBundle:SomeOtherCtrl:someOtherAction }
methods: [GET]
requirements:
formId: \d+
fileName: ^([a-fA-F0-9]{32}(?:\.[a-zA-Z0-9]{1,222})?)$
Now the request URI "http://servername/web/app_dev.php/admin/download/12/23d2fff7f606e93acac9ede5b4e2b394.png" matches the first, but I want to match the second...what is the official scenario in cases like this?
You should change the order in which you are importing routes, so the route http://servername/web/app_dev.php/admin/download/12/23d2fff7f606e93acac9ede5b4e2b394.png will trigger the route_in_bundle_b first and the routes that doesn't have the download segment will not trigger it and will trigger the route_in_bundle_a rule.
I'm working with Symfony2.3.4 and PHP5.6.3
This happens only when I AM LOGGED IN PROD ENV, while I'm not or when I'm in dev env(logged or not) nothing bad happens, I can go anywhere in my site(security is not implemented yet).
Has anyone run into this issue already? I really don't know what other info you'd need to help me, please feel free to yell back for extra info.
routing.yml
homepage:
pattern: /homepage/
defaults: { _controller: GCBundle:Default:homepage }
UserBundle:
resource: "#UserBundle/Resources/config/routing.yml"
prefix: /user/
GCBundle:
resource: "#GCBundle/Resources/config/routing.yml"
prefix: /gc/
ReportsBundle:
resource: "#ReportsBundle/Resources/config/routing.yml"
prefix: /reports/
routing_dev.yml
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "#SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
#AcmeDemoBundle routes (to be removed)
_acme_demo:
resource: "#AcmeDemoBundle/Resources/config/routing.yml"
thanks
Let's say I've got a website with multiple (sub)domains:
acme.com (USA)
acme.nl (Netherlands)
be.acme.eu (Belgium)
de.acme.eu (Germany)
fr.acme.eu (France)
etc...
I thought this should be very simple to configure, so I made this routing.yml:
usa:
host: "acme.com"
resource: "#WebsiteBundle/Controller/"
type: annotation
defaults:
country: "en"
netherlands:
host: "acme.nl"
resource: "#WebsiteBundle/Controller/"
type: annotation
defaults:
country: "nl"
europe:
host: "{country}.acme.eu"
resource: "#WebsiteBundle/Controller/"
type: annotation
But if I run router:debug, only the last route (in this case {country}.acme.eu) shows up. If I change to order, the last option shows up.
How can I use different (sub)domains for all my countries?
This is because all the routes point to one resource. Every later route will override routes defined before.
But you can use another solution:
main_route:
host: "{country}.acme.{domain}"
resource: "#WebsiteBundle/Controller/"
type: annotation
defaults:
country: "en"
Then check in some listener before controller for valid url and process parameters.
You should use Symfony's hostname routing.
So your routes would look like:
international_homepages:
path: /
host: "{subdomain}.acme.{extension}"
defaults:
_controller: AcmeBundle:Main:defaultHomepage
subdomain: www
extension: com